How to use user control in windows forms in c#




















Forms Assembly: System. Provides an empty control that can be used to create other controls. Note You might consider creating a namespace that contains several classes of user controls and compiling it into one DLL. In this article. Inherited from ScrollableControl. Determines whether the user has enabled full window drag. Inherited from Control. Gets or sets the description of the control used by accessibility client applications.

Gets or sets the name of the control used by accessibility client applications. Gets or sets the accessible role of the control. Gets or sets the active control on the container control. Inherited from ContainerControl. Gets or sets a value indicating whether the control can accept data that the user drags onto it. Gets or sets the dimensions that the control was designed to. Gets the scaling factor between the current and design-time automatic scaling dimensions.

Gets or sets the automatic scaling mode of the control. Gets or sets the size of the auto-scroll margin. Gets or sets the minimum size of the auto-scroll. Gets or sets the location of the auto-scroll position. This property is not relevant for this class. Gets or sets how the control performs validation when the user changes focus to another control. Gets or sets the background color for the control. Gets or sets the background image displayed in the control.

Gets a value indicating whether the control can receive focus. Determines if events can be raised on the control. Gets a value indicating whether the control can be selected. Gets or sets a value indicating whether the control has captured the mouse. Gets the rectangle that represents the client area of the control. Gets or sets the height and width of the client area of the control. Gets the name of the company or creator of the application containing the control.

Inherited from Component. Gets or sets the shortcut menu associated with the control. Gets the collection of controls contained within the control. Gets a value indicating whether the control has been created. Gets the required creation parameters when the control handle is created.

Gets the current run-time dimensions of the screen. Gets or sets the cursor that is displayed when the mouse pointer is over the control. Gets the data bindings for the control. Gets or sets the default cursor for the control.

Gets the space, in pixels, that is specified by default between controls. Gets the internal spacing, in pixels, of the contents of a control. Gets the DPI value for the display device where the control is currently being displayed. Gets the rectangle that represents the virtual display area of the control. Gets the dock padding settings for all edges of the control.

Gets or sets a value indicating whether the control can respond to user interaction. Gets a value indicating whether the control has input focus. Gets or sets the font of the text displayed by the control.

Gets or sets the height of the font of the control. Gets or sets the foreground color of the control. Gets the window handle that the control is bound to. Gets a value indicating whether the control contains one or more child controls. Gets or sets the height of the control. Gets the characteristics associated with the horizontal scroll bar. Gets or sets a value indicating whether the horizontal scroll bar is visible.

Gets or sets the IME mode of a control. Gets or sets a value indicating whether the control is visible to accessibility applications.

Gets a value indicating whether the control has been disposed of. Gets a value indicating whether the control has a handle associated with it. Gets a value indicating whether the control is mirrored.

Gets a cached instance of the control's layout engine. Gets or sets the space between controls. Gets or sets the name of the control. Gets or sets padding within the control. Gets or sets the parent container of the control. Gets the form that the container control is assigned to. Gets the size of a rectangular area into which the control can fit.

Gets the product name of the assembly containing the control. Gets the version of the assembly containing the control. Gets a value indicating whether the control is currently re-creating its handle. Gets or sets the window region associated with the control. This property is now obsolete. Gets or sets a value indicating whether the control redraws itself when resized. Gets a value that determines the scaling of child controls. Gets a value indicating whether the control should display focus rectangles.

Gets or sets the site of the control. Gets or sets the height and width of the control. Gets or sets the tab order of the control within its container.

Gets or sets the object that contains data about the control. Gets the characteristics associated with the vertical scroll bar. Gets or sets a value indicating whether the control and all its child controls are displayed. Gets or sets a value indicating whether the vertical scroll bar is visible. Gets or sets the width of the control.

AdjustFormScrollbars Boolean. BeginInvoke Action. BeginInvoke Delegate. BeginInvoke Delegate, Object[]. Brings the control to the front of the z-order. Contains Control. Retrieves a value indicating whether the specified control is a child of the control.

Creates a new accessibility object for the control. Creates a new instance of the control collection for the control. Creates a handle for the control. CreateObjRef Type. Inherited from MarshalByRefObject.

DefWndProc Message. Sends the specified message to the default window procedure. Destroys the handle associated with the control. Dispose Boolean. Begins a drag-and-drop operation. DrawToBitmap Bitmap, Rectangle. Supports rendering to the specified bitmap. EndInvoke IAsyncResult. Equals Object. Determines whether the specified object is equal to the current object.

Inherited from Object. Retrieves the form that the control is on. Sets input focus to the control. GetChildAtPoint Point. Retrieves the child control that is located at the specified coordinates. Serves as the default hash function.

GetNextControl Control, Boolean. Retrieves the next control forward or back in the tab order of child controls. GetPreferredSize Size. Retrieves the size of a rectangular area into which a control can be fitted.

Retrieves the bounds within which the control is scaled. GetScrollState Int Determines whether the specified flag has been set. GetService Type. GetStyle ControlStyles. Retrieves the value of the specified control style bit for the control. Determines if the control is a top-level control. Conceals the control from the user. Obtains a lifetime service object to control the lifetime policy for this instance. Called after the control has been added to another container.

Invalidates the entire surface of the control and causes the control to be redrawn. Invalidate Boolean. Invalidate Rectangle. Invalidate Rectangle, Boolean. Invalidate Region. Invalidate Region, Boolean. Invoke Action. Executes the specified delegate on the thread that owns the control's underlying window handle. Invoke Delegate. Invoke Delegate, Object[]. IsInputChar Char.

To add an Icon to the control use the ToolboxBitmap attribute to provide your Control a visual appearance. InitializeComponent ;. ToString ;. The following is the complete code:. Build the solution.

Now let us try to add the control to the project. Create a new Windows Application Project. Now the DLL has been added to your project. Let us add the control to our Toolbox. Viewed 26k times. Is there any way to do that? Improve this question. Spoon Yukina Spoon Yukina 4 4 gold badges 13 13 silver badges 26 26 bronze badges. You can treat your user control just like you do any other control that is added to a form. So, if it's hidden, in the button click event, just call UserControl.

Add a comment. Active Oldest Votes. You can dynamically add the user control to the forms Controls collection. Fill; this. Add uc ;. Select windows Control Library from Visual studio templates for Windows applications. Change the name to your desired name Here I named LoginControl. Remember to rename it at all places properly.

Create your user control User Interface. In this tutorial I am just writing a small login control as below. Name the 2 textboxes as txtUserId and txtPassword and button as btnLogin. Write the user control code logic. An example given below Yes, it is a simple logic just to explain only. In real scenarios, these properties shall be set by values retrieved from the database or any other data store.

During Login button click user credentials are compared with the user entered login credentials in the textbox controls txtUserId and txtPassword. If both matches user will be allowed to log in.



0コメント

  • 1000 / 1000