DOTNET desktop programming plan. Down-down box. Color drop-down box similar to Word

xiaoxiao2021-03-06  33

First look at the picture. Implementation function: 1) Drop the color selection dialog. 2) The background window does not lose focus .3) Click more calls Windows Standard color pick dialog Select color. Development background: See some articles online These functions can be basically implemented, but most of the way to transfer the focus to the background window after the front window, or put the front window Show by closing the front desk window, or simply uses a confection (with ordinary Controls If the range exceeds the range of the background window, the Windows built-in menu or drop-down box does not make it, the front desk triggers the event that lost the focus event, and will not be blocked, holding a programmer Belief, in the 9CBS Forum, have a number of posts (400 points), and the continuous effort has finally been. I would like to thank the colleagues of the 9CBS, there is no such world (Ha) without you. Not much nonsense, enter the topic. Program implementation code analysis: 1) The base Windows API class used by the article. Using system; using system.runtime.interopservices; ///

/// system call, all WINDOWS API-related places may have been useless, specifically explain the emotion of MSDN /// Public Class SystemShell {public const int GWL_STYLE = -16; // public const int GWL_EXSTYLE = -20; // public const int WS_VISIBLE = 0x10000000; public const int WS_CHILDWINDOW = 0x40000000; // public const int WS_CLIPSIBLINGS = 0x04000000; // public const int WS_CLIPCHILDREN = 0x02000000; // public const int WS_BORDER = 0x00800000; // public const long WS_THICKFRAME = 0x00040000; // public const long WS_OVERLAPPED = 0x00000000; // public const long WS_DLGFRAME = 0x00400000; // public const long WS_EX_TOOLWINDOW = 0x00000080; / / public const INT WM_NCPAINT = 0x0085; Public const INT WM_AACTIVATEAPP = 0X

001C

; // public const int WM_ERASEBKGND = 0x0014; [DllImport ( "user32.dll", CharSet = CharSet.Auto)] public static extern long SetWindowLong (IntPtr hWnd, int nIndex, long dwNewLong); [DllImport ( "user32.dll" , CharSet = CharSet.Auto)] public static extern long GetWindowLong (IntPtr hWnd, int nIndex); //[DllImport("user32.dll ", CharSet = CharSet.Auto)] // public static extern int SendMessage (IntPtr hWnd, int msg, int wParam, int lParam); //[DllImport("user32.dll ", CharSet = CharSet.Auto)] // public static extern int GetWindowRect (IntPtr hWnd, ref System.Drawing.Rectangle lpRect); private SystemShell () {// // TODO: Add constructor logic //}} This article pops up the base class (code processing flow in accordance with the label navigation) ///

/// noactform to implement pop-up window Base class. /// public class noactform: system.windows.Forms.form {/// // / / The necessary designer variables. /// private system.componentmodel.container Components = NULL; public noactform (): base () {// // Windows Form Designer Support for // InitializationComponent ();} /// < Summary> /// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {Components.dispose ();}} Base.Dispose (DISPOSION);} #Region Windows Form The code generated by the designer /// /// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void initializecomponent () {/// noactform // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (292, 273 ); // (1) Do not title icon and text attribute, this.ControlBox = false; this.formo.formorderstyle = system.windows.forms.formorderstyle.FixedDialog; this.name = "noactform"; this.startPosition = system.windows. Forms.FormStartPosition.Manual; this.Load = new System.EventHandler (this.NoActForm_Load);} #endregion private void NoActForm_Load (object sender, System.EventArgs e) {// if not in design mode if (this.DesignMode! ) {// No Owner is not possible (this.owner == null) {throw new applicationException ("not owner form");} this.showintaskbar = false; // (2) The key here Any window should be added WS_CHILDWINDOW style can be long style = systemsh ell.GetWindowLong (this.Handle, SystemShell.GWL_STYLE); Style | = SystemShell.WS_CHILDWINDOW; SystemShell.SetWindowLong (this.Handle, SystemShell.GWL_STYLE, Style);}} ///

/// show their definition /// /// To get out of the window public virtual void show (control CTL) {// Location Rectangle Rect = CTL.Rectangletoscreen (New Rectangle (0,0, CTL.Width, CTL.HEight)); this.Top = Rect.Top CTL.HEight; Rectangle ScreenRect =

Screen.primaryScreen.Workingarea; IF (this.right> ScreenRect.width || this.bottom> ScreenRect.Height) {this.left = Rect.width; this.top = Rect.Top - This.height;} this.show ();} ///

/// Override wndproc /// /// protected override void WNDPROC (REF Message M) {// (3) If the entire program is lost, hide if (msg == systemshell.wm_activateapp && m.wparam == INTPTR.ZERO) {this.hide ();} Base.WndProc (Ref m);}} Specific implementation (Code processing flow in accordance with labeling) /// /// ColorSelectform's summary description. /// (1) Inherit noactform /// public class colorslectform: noactform {/// ///// public delegate void mouseselectcolor (color selectcolor); /// < summary> /// (2) color selection event is triggered when a window is present obtain color /// public event MouseSelectColor SelectColor; private Control _ShowCtl; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms .Label label1; private system.windows.forms.colordialog colorDialog1; /// // / / The necessary designer variables.

/// private system.componentmodel.container component = null; public colorselectform (): base () {// // Windows Form Designer Support for // InitializeComponent (); this.mousedown = New MouseEventHandler (ColorSelectForm_MouseDown); this.MouseMove = new MouseEventHandler (ColorSelectForm_MouseMove); // // TODO: Add any constructor code after InitializeComponent call //} ///

/// clean up all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {Components.dispose ();}} Base.Dispose (DISPOSION);} #Region Windows Form The code generated by the designer /// /// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (ColorSelectForm)); this.pictureBox1 = new System.Windows.Forms.PictureBox (); this. label1 = new System.Windows.Forms.Label (); this.colorDialog1 = new System.Windows.Forms.ColorDialog (); this.SuspendLayout (); // // pictureBox1 // this.pictureBox1.Cursor = System.Windows .Forms.cursors.cross; this.picturebox1.dock = system.windows.Forms.dockStyle.top; // (3) Place the PictureBox1.Image This.PictureBox1.image = ((System.drawing.Image ("PictureBox1.image"))))); this.picturebox1.location = new system.drawing.point (0, 0); this.picturebox1.name = "picturebox1"; this.picturebox1.size = new System.drawing.size (194, 289); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; // // label1 // this.label1.BackColor = System.Drawing.SystemColors.Control; this.label1.BorderStyle = System.Windows.Forms.BorderStyle .Fixed3d; this.label1.dock = system.windows.forms.dockstyle.fill; this.label1.location = new system.drawing.point (0, 289); this.label1.name = "label1"; this.Label1 .Size = new system.drawing.size (194, 25); this.label1.tabindex = 1; this.label1.text = "More ..."

this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // ColorSelectForm // this.AutoScale = false; this.AutoScaleBaseSize = new System.Drawing.Size (6, 14); this.ClientSize = new System. Drawing.size (194, 314); this.controlbox = false; this.controls.add (this.label1); this.Controls.add (this.PictureBox1); this.cursor = system.windows.Forms.cursors.cross This.formBorderstyle = system.windows.Forms.FormBorderstyle.FixedDialog; this.name = "colorselectform"; this.text = ""; this.ResumeLayout (false);} #ENDREGION ///

/// 4) Package Show /// /// public override void show (control ctl) {_showctl = CTL; Owner.cursor = Cursors.cross; base.s HOW (CTL); // Show immediately captures this.capture = true;} /// /// (6) If the mouse is pressed to perform a series of processing /// /// < Param name = "sender"> /// private void colorSelectform_mousedown (Object sender, mouseeventargs e) {// Release mouse this.capture = false; point pt = Control.mouseposition; color cl = color.empty; while {// is in the window range IF (! (Pt.x>

this.right || pt.x this.bottom || pt.y rest.right |) on Label1 (! (Pt.x> Rect.x || Pt. Y> Rect.bottom || Pt.Y Rect.right || Pt.x r Ect.bottom || pt.y

转载请注明原文地址:https://www.9cbs.com/read-62650.html

New Post(0)