當前位置: 首頁>>代碼示例>>C#>>正文


C# OpenFileDialog.GetFileItem方法代碼示例

本文整理匯總了C#中System.Windows.Forms.OpenFileDialog.GetFileItem方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenFileDialog.GetFileItem方法的具體用法?C# OpenFileDialog.GetFileItem怎麽用?C# OpenFileDialog.GetFileItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.OpenFileDialog的用法示例。


在下文中一共展示了OpenFileDialog.GetFileItem方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestDragDrop

        public void TestDragDrop()
        {
            Trace.WriteLine("TestDragDrop==========================================================");
            var w = this.LaunchNotepad();

            Rectangle treeBounds = this.TreeView.Bounds;

            Trace.WriteLine("OpenFileDialog");
            w.InvokeAsyncMenuItem("openToolStripMenuItem");
            Window openDialog = w.WaitForPopup();
            Trace.WriteLine("Opening '" + TestDir + "UnitTests'");
            openDialog.SendKeystrokes(TestDir + "UnitTests{ENTER}");
            Sleep(1000);

            // Drag/drop from open file dialog into xml notepad client area.
            OpenFileDialog dialogWrapper = new OpenFileDialog(openDialog);

            Point drop = GetDropSpot(openDialog, treeBounds);
            Trace.WriteLine("Drop spot = " + drop.ToString());

            AutomationWrapper item = dialogWrapper.GetFileItem("test1.xml");

            if (item == null)
            {
                // try finding the item using the keyboard.
                throw new Exception("File item not found");
            }

            Rectangle ibounds = item.Bounds;
            Point iloc = new Point(ibounds.Left + 10, ibounds.Top + 10);
            Trace.WriteLine("Dragging from " + iloc.ToString());
            Mouse.MouseDragDrop(iloc, drop, 5, MouseButtons.Left);
            Sleep(1000);
            dialogWrapper.DismissPopUp("{ESC}");

            // need bigger window to test drag/drop
            w.SetWindowSize(800, 600);

            w.InvokeMenuItem("collapseAllToolStripMenuItem");
            w.InvokeMenuItem("expandAllToolStripMenuItem");

            // Test mouse wheel
            AutomationWrapper tree = this.TreeView;
            CheckProperties(tree);

            w.SendKeystrokes("{HOME}");
            Cursor.Position = tree.Bounds.Center();
            Sleep(500); // wait for focus to kick in before sending mouse events.
            Mouse.MouseWheel(-120 * 15); // first one doesn't get thru for some reason!
            Sleep(500);
            Mouse.MouseWheel(120 * 15);
            Sleep(500);

            // Test navigation keys
            w.SendKeystrokes("{HOME}");
            CheckNodeValue("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            w.SendKeystrokes("{END}");
            CheckNodeValue("<!--last comment-->");
            w.SendKeystrokes("{PGUP}{PGDN}{UP}{UP}");
            CheckNodeValue("Name");

            // Get AutomationWrapper to selected node in the tree.
            AutomationWrapper ntv = this.NodeTextView;
            CheckProperties(ntv);
            // mouse down in node text view
            AutomationWrapper node = ntv.GetSelectedChild();
            node = node.Parent.NextSibling; // Office node.
            CheckNodeName(node, "Office");
            Rectangle bounds = node.Bounds;
            Mouse.MouseClick(bounds.Center(), MouseButtons.Left);

            // test edit of node value using AccessibilityObject
            string office = "35/1682";
            node.Value = office;

            // for some odd reason the paste expands the element.
            Sleep(300);
            CheckNodeValue(office);  // confirm via copy operation

            node = tree.GetSelectedChild();
            if (node == null) {
                throw new ApplicationException("Selected node not found");
            }
            CheckProperties(node);
            CheckNodeName(node, "Office");
            node.AddToSelection();

            // test edit of node name using accessibility.
            this.SetNodeName(node, "MyOffice");
            CheckNodeValue("MyOffice");  // confirm via copy operation

            // Test that "right arrow" moves over to the nodeTextView.
            w.SendKeystrokes("{RIGHT}{DOWN}{RIGHT}");
            CheckNodeValue("35/1682");  // confirm via copy operation

            Undo(); // make sure we can undo node name change!
            Undo(); // make sure we can undo node value change (while #text is expanded)!
            this.TreeView.SetFocus();
            CheckNodeValue("Office");

//.........這裏部分代碼省略.........
開發者ID:dbremner,項目名稱:xmlnotepad,代碼行數:101,代碼來源:UnitTest1.cs


注:本文中的System.Windows.Forms.OpenFileDialog.GetFileItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。