当前位置: 首页>>代码示例>>C#>>正文


C# Control.Focus方法代码示例

本文整理汇总了C#中Control.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Focus方法的具体用法?C# Control.Focus怎么用?C# Control.Focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Control的用法示例。


在下文中一共展示了Control.Focus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetInitialFocus

        /// <summary>
        /// Set the initial focus on the given control
        /// </summary>
        /// <param name="window">Childwindow for which the focus must be set</param>
        /// <param name="controlFocus">Control to set the focus on</param>
        public static void SetInitialFocus(this Window window, Control controlFocus)
        {
            var routedHandler = default(RoutedEventHandler); // set to null to prevent unassigned compiler error
            routedHandler = delegate
                            {
                                controlFocus.Focus();
                                var textBox = controlFocus as TextBox;
                                if (null != textBox)
                                {
                                    textBox.SelectAll();
                                }
                                // unsubscribe after first execute
                                window.GotFocus -= routedHandler;
                            };

            window.GotFocus += routedHandler;
        }
开发者ID:erashid,项目名称:Extensions,代码行数:22,代码来源:WindowExtension.cs

示例2: ShowDropDownControl

		private void ShowDropDownControl (Control control, bool resizeable) 
		{
			dropdown_form.Size = control.Size;
			control.Dock = DockStyle.Fill;

			if (resizeable) {
				dropdown_form.Padding = dropdown_form_padding;
				dropdown_form.Width += dropdown_form_padding.Right;
				dropdown_form.Height += dropdown_form_padding.Bottom;
				dropdown_form.FormBorderStyle = FormBorderStyle.Sizable;
				dropdown_form.SizeGripStyle = SizeGripStyle.Show;
			} else {
				dropdown_form.FormBorderStyle = FormBorderStyle.None;
				dropdown_form.SizeGripStyle = SizeGripStyle.Hide;
				dropdown_form.Padding = Padding.Empty;
			}

			dropdown_form.Controls.Add (control);
			dropdown_form.Width = Math.Max (ClientRectangle.Width - SplitterLocation - (vbar.Visible ? vbar.Width : 0), 
							control.Width);
			dropdown_form.Location = PointToScreen (new Point (grid_textbox.Right - dropdown_form.Width, grid_textbox.Location.Y + row_height));
			RepositionInScreenWorkingArea (dropdown_form);
			Point location = dropdown_form.Location;

			Form owner = FindForm ();
			owner.AddOwnedForm (dropdown_form);
			dropdown_form.Show ();
			if (dropdown_form.Location != location)
				dropdown_form.Location = location;

			System.Windows.Forms.MSG msg = new MSG ();
			object queue_id = XplatUI.StartLoop (Thread.CurrentThread);
			control.Focus ();
			while (dropdown_form.Visible && XplatUI.GetMessage (queue_id, ref msg, IntPtr.Zero, 0, 0)) {
				switch (msg.message) {
					case Msg.WM_NCLBUTTONDOWN:
				    case Msg.WM_NCMBUTTONDOWN:
				    case Msg.WM_NCRBUTTONDOWN:
				    case Msg.WM_LBUTTONDOWN:
				    case Msg.WM_MBUTTONDOWN:
				    case Msg.WM_RBUTTONDOWN:
				    	if (!HwndInControl (dropdown_form, msg.hwnd))
							CloseDropDown ();
					break;
					case Msg.WM_ACTIVATE:
					case Msg.WM_NCPAINT:
				 		if (owner.window.Handle == msg.hwnd)
							CloseDropDown ();
					break;						
				}
				XplatUI.TranslateMessage (ref msg);
				XplatUI.DispatchMessage (ref msg);
			}
			XplatUI.EndLoop (Thread.CurrentThread);			
		}
开发者ID:nlhepler,项目名称:mono,代码行数:55,代码来源:PropertyGridView.cs


注:本文中的Control.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。