Esempio n. 1
0
        /// <summary>
        /// 利用映射方法对 ToolStrip 控件进行双缓冲处理,解决闪烁问题
        /// </summary>
        /// <param name="TargetToolStrip">目标ToolStrip控件</param>
        /// <param name="EnableDoubleBuffer">是否启用双缓冲处理</param>
        public static void DoubleBufferedToolStrip(this ToolStrip TargetToolStrip, bool EnableDoubleBuffer)
        {
            Type         lvType = TargetToolStrip.GetType();
            PropertyInfo pi     = lvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);

            pi.SetValue(TargetToolStrip, EnableDoubleBuffer, null);
        }
 private Button GetButtonFromTsmi(ToolStripMenuItem tsmi)
 {
     if (tsmi != null)
     {
         ToolStrip owner = tsmi.GetCurrentParent();
         if (owner.GetType() == typeof(ContextMenuStrip))
         {
             Control Source = ((ContextMenuStrip)owner).SourceControl;
             if (Source != null && Source.GetType() == typeof(Button))
             {
                 return((Button)Source);
             }
         }
     }
     return(null);
 }
Esempio n. 3
0
 protected override void OnPaint(PaintEventArgs e)
 {
     try
     {
         using (var tempToolStrip = new ToolStrip())
         {
             Type t    = typeof(ToolStrip).Assembly.GetType("System.Windows.Forms.ToolStripGrip");
             var  ctor = t.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0];
             using (var fakeGrip = (ToolStripButton)ctor.Invoke(new object[] { }))
             {
                 typeof(ToolStripItem).GetField("bounds", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(fakeGrip, e.ClipRectangle);
                 tempToolStrip.GetType().GetField("toolStripGrip", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(tempToolStrip, fakeGrip);
                 var args = new ToolStripGripRenderEventArgs(e.Graphics, tempToolStrip);
                 Owner.Renderer.DrawGrip(args);
             }
         }
     }
     catch
     {
         base.OnPaint(e);
     }
 }
Esempio n. 4
0
        public void GetCurrentParent()
        {
            ToolStripMenuItem tsmiFile  = new ToolStripMenuItem("File");
            ToolStripMenuItem tsmiHelp  = new ToolStripMenuItem("Help");
            ToolStripMenuItem tsmiQuit  = new ToolStripMenuItem("Quit");
            ToolStripMenuItem tsmiAbout = new ToolStripMenuItem("About");

            tsmiFile.DropDownItems.Add(tsmiQuit);
            tsmiHelp.DropDownItems.Add(tsmiAbout);
            MenuStrip menu = new MenuStrip();

            menu.Items.Add(tsmiFile);
            menu.Items.Add(tsmiHelp);

            ToolStrip parent = tsmiFile.GetCurrentParent();

            Assert.IsNotNull(parent, "A1");
            Assert.AreEqual(parent.GetType().Name, typeof(MenuStrip).Name, "A2");
            Assert.AreEqual(parent, menu, "A3");

            //because it's not visible?:
            Assert.IsNull(tsmiQuit.GetCurrentParent(), "A4");
        }
Esempio n. 5
0
        public static void Test(Form form)
        {
            bool AutomaticTests = true;
            bool showCloneForm  = !AutomaticTests;

#if !DEBUG
            if (!AutomaticTests)
            {
                MessageBox.Show("The application should be compiled in DEBUG mode");
            }
#endif

            // - - - -

            TestResults.Clear();

            {
                string title = "ToolStrip contains a FlowLayoutSetting that builds using an inherited private field.";
                var    data  = new ToolStrip();
                data.LayoutStyle = ToolStripLayoutStyle.Flow;

                var  data2 = EasySerializeThenDeserializeWinForm(data);
                bool ok    = (data2 != null) && data2.LayoutStyle == ToolStripLayoutStyle.Flow;
                AddTestResult(title + " {" + data.GetType().Name + "}", ok);
                if (!AutomaticTests)
                {
                    Debugger.Break();
                }
            }

            {
                string title = "ControlBindingsCollection";
                var    data  = new Form();
                data.DataBindings.Add("Width", data, "Height");

                var  data2 = EasySerializeThenDeserializeWinForm(data.DataBindings);
                bool ok    = (data2 != null) && data2.Count == 1;
                AddTestResult(title + " {" + data.GetType().Name + "}", ok);
                if (!AutomaticTests)
                {
                    Debugger.Break();
                }
            }

            {
                string title = "Main Form";
                var    data  = new Form();
                var    t     = data.Text;
                data.Text = "fen2";
                data.Controls.Add(new Label()
                {
                    Text = "Hello"
                });
                var  data2 = EasySerializeThenDeserializeWinForm(data);
                bool ok    = (data2 != null);
                AddTestResult(title + " {" + data.GetType().Name + "}", ok);
                data.Text     = t;
                data2.Visible = false;
                if (showCloneForm)
                {
                    data2.ShowDialog();
                }
                else
                {
                    data2.WindowState = FormWindowState.Minimized;
                    data2.Show();
                }
                data2.Close();
                if (!AutomaticTests)
                {
                    Debugger.Break();
                }
            }

            {
                string title = "ControlBindingsCollection + simple Form";
                var    data  = new Form();
                data.DataBindings.Add("Width", data, "Height");
                var  data2 = EasySerializeThenDeserializeWinForm(data);
                bool ok    = (data2 != null);
                AddTestResult(title + " {" + data.GetType().Name + "}", ok);
                if (!AutomaticTests)
                {
                    Debugger.Break();
                }
            }

            {
                string title = "BindingContext";
                var    data  = new BindingContext();
                var    data2 = EasySerializeThenDeserializeWinForm(data);
                bool   ok    = (data2 != null);
                AddTestResult(title + " {" + data.GetType().Name + "}", ok);
                if (!AutomaticTests)
                {
                    Debugger.Break();
                }
            }



            if (!AutomaticTests)
            {
                bool AllOK =
                    TestResults.All(p => p.Success);
                Debugger.Break();
            }
        }
Esempio n. 6
0
        private void PopulateToolStrip(ToolStrip Strip, XmlNode ToolStripDescriptor, bool ImageAboveText)
        {
            // --------------------------------------------------------------
            // This method populates the specified context menu given the
            // specified descriptor data.
            // --------------------------------------------------------------

            foreach (XmlNode ChildDescriptor in XmlHelper.ChildNodes(ToolStripDescriptor, ""))
            {
                if (XmlHelper.Type(ChildDescriptor) == "ImageSize")
                {
                    Strip.ImageList = ImageList(ChildDescriptor.InnerText);
                }
                else if (XmlHelper.Type(ChildDescriptor) == "Item")
                {
                    ToolStripItem Item = CreateToolStripItem(Strip, ChildDescriptor.InnerText);
                    if (ImageAboveText)
                    {
                        Item.TextImageRelation = TextImageRelation.ImageAboveText;
                    }
                }
                else if (XmlHelper.Type(ChildDescriptor) == "DropDownItem")
                {
                    string  DropDownActionName           = XmlHelper.Attribute(ChildDescriptor, "action");
                    XmlNode Action                       = XmlHelper.Find(ActionFile, "/Folder/Actions/" + DropDownActionName);
                    ToolStripDropDownItem DropDownButton = null;
                    ToolStripDropDown     DropDownStrip  = null;
                    if (Strip.GetType().ToString() == "System.Windows.Forms.ToolStrip")
                    {
                        DropDownButton = new ToolStripDropDownButton();
                        DropDownStrip  = new ToolStripDropDownMenu();
                    }
                    else
                    {
                        DropDownButton = new ToolStripMenuItem();
                        DropDownStrip  = new ToolStripDropDownMenu();
                    }
                    DropDownButton.Text         = XmlHelper.Value(Action, "text");
                    DropDownButton.ImageIndex   = ImageIndexForAction(Action, Strip.ImageList.Tag.ToString());
                    DropDownButton.ImageScaling = ToolStripItemImageScaling.None;
                    DropDownButton.AutoToolTip  = false;
                    DropDownButton.Tag          = DropDownActionName;
                    DropDownButton.Enabled      = IsActionAllowed(Action);
                    if (ImageAboveText)
                    {
                        DropDownButton.TextImageRelation = TextImageRelation.ImageAboveText;
                    }
                    DropDownStrip.ImageList    = ImageList("SmallIcon");
                    DropDownStrip.ItemClicked += ActionOnClick;
                    //add a handler
                    PopulateToolStrip(DropDownStrip, ChildDescriptor, false);
                    //recursion call
                    DropDownButton.DropDown = DropDownStrip;
                    Strip.Items.Add(DropDownButton);
                }
                else if (XmlHelper.Type(ChildDescriptor) == "Separator")
                {
                    Strip.Items.Add(new ToolStripSeparator());
                }
                else if (XmlHelper.Type(ChildDescriptor) == "RecentFileList")
                {
                    foreach (string FileName in Configuration.Instance.GetFrequentList())
                    {
                        ToolStripItem Item = Strip.Items.Add(FileName);
                        Item.ImageIndex  = -1;
                        Item.Tag         = "";
                        Item.ToolTipText = "Open this file";
                        if (ImageAboveText)
                        {
                            Item.TextImageRelation = TextImageRelation.ImageAboveText;
                        }
                    }
                }
            }
        }