Click here to Skip to main content
15,885,366 members
Everything / Custom controls

Custom controls

custom-controls

Great Reads

by Martin Mitáš
How to support scrolling within your controls.
by Dejan Mauer
Free and easy way to access a web camera by using the Aforge library.
by HateCoding
A tiny custom list control
by Niemand25
A simple way to place any ObjectListView inside a ComboBox

Latest Articles

by Vassili Kravtchenko-Berejnoi
A generic workaround for auto-generating multiple custom columns in a WPF DataGrid in case where the data class has multiple properties of the same type
by Martin Mitáš
How to support scrolling within your controls.
by David Fine
Using Attached DependencyProperty to prevent closing of Popup embedded in ToggleButton
by Niemand25
A simple way to place any ObjectListView inside a ComboBox

All Articles

Sort by Score

Custom controls 

26 Feb 2018 by Martin Mitáš
How to support scrolling within your controls.
22 May 2013 by Dejan Mauer
Free and easy way to access a web camera by using the Aforge library.
23 May 2012 by VJ Reddy
For the properties of the object set at design to be persisted in the form the DesignerSerializationVisibilityAttribute with the argument DesignerSerializationVisibility.Content is to be used like _Public ReadOnly...
8 Nov 2016 by Niemand25
A simple way to place any ObjectListView inside a ComboBox
17 May 2023 by Olivier Levrey
[Description("Very basic slider control with selection range.")] public partial class SelectionRangeSlider : UserControl { /// /// Minimum value of the slider. /// [Description("Minimum value of the...
24 Jan 2012 by Shahin Khorshidnia
Hello,I did almost a same thing but by WPF for a company.I made some Icons that they where connected together with lines. (Like VISIO)I've never seen any prepared user control for connector point. At leat I don't know.I built it and I think you have to build.1. Save dimensions...
25 Jan 2012 by Sergey Alexandrovich Kryukov
My advice is: don't do it this way. This is possible in principle; I knew few attempts, all pretty much unsuccessful; and it's clear why.I explained what to do in my past solution: Drawing Lines between mdi child forms[^].The question is not exactly the same as yours, but the right...
25 Jan 2012 by Espen Harlinn
I think you are looking for something like this:WPF Diagram Designer - Part 1[^]WPF Diagram Designer - Part 2[^]WPF Diagram Designer - Part 3[^]WPF Diagram Designer - Part 4[^]The articles are well written and the concepts fundamental to WPF designer integration, but if you are new...
25 Jan 2012 by Sergey Alexandrovich Kryukov
Now, lets turn to WPF and let me give you some further ideas before we close this discussion and you continue on your own. I hope you will choose to accept this one formally, too. (You can click green "Accept" button on more than one.)With WPF, you can put all your diagram elements on the...
16 Jan 2011 by Sergey Alexandrovich Kryukov
If this is ASP.NET you really need to filter events in the client part (in the Web browser). Please see the Answer by Jason C Daniels who provided very clear motivation.I already answered similar question (cannot find it...). With Javascript, you can filter out characters not allowed in the...
16 Jan 2011 by Jason C Daniels
In order to process key-strokes in a webpage, you MUST write some javascript. With that said, you *could* call into the codebehind in the javascript handler for the keypress... but it will be horribly inefficient.Why? Because you will cause network traffic, and therefore a very noticable...
9 Jun 2011 by OriginalGriff
You can do that, but your reasoning is slightly flawed."I decided to do it this way in order to have only one 'onclick' event handler that serves all of the PaintedPanel instances, rather than creating a grid of Panels within my main form logic and having to code multiple event handlers for...
16 Jun 2011 by BobJanova
WinForms radio buttons are standard Windows controls, and therefore it's quite difficult to perform small extensions on them.A radio button, button and text together, is one control. If you want to change its appearance, you can override OnPaint, but you need to draw both parts.I found...
14 Jul 2011 by Sergey Alexandrovich Kryukov
You don't need to add any thread-safe features in the custom controls. Anyway, a non-UI thread cannot call any UI methods or properties. Working with UI from the non-UI thread is nevertheless possible, but the calls are dispatched to the UI thread using inter-thread invocation...
5 Jun 2012 by OriginalGriff
The chances are that because you are sending this from a ValueChanged event handler, the effect of the SendKeys is to send a RIGHT key to the current control - i.e. the CustomDateTimePicker, and that it is (for whatever reason) causing a ValueChanged Event. Which sends a RIGHT, which causes......
1 Jul 2023 by Graeme_Grant
Microsoft Excel moves the cursor down a row if the enter key is used. I would recommend using this as it is familiar. However, to move the cursor right, not down, on using the Enter key, it is possible. The following code will wrap the cursor...
26 Jan 2010 by DaveyM69
All public properties that have a setter are serialized to the designer file so long as they aren't decorated with[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]If a property has a default value (by either DefaultValue attribute or ShouldSerializePropertyName and...
26 Jan 2010 by DaveyM69
If you goto the definition for UserControl you will see that the Text property is like this:[Bindable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public...
15 Nov 2010 by Chanchal Kumar Ghosh
To understand my question first see the image below:br mode="hold" />This is the picture of the combo box in the editor window. I just want to create a custom control like this. Here I want to know how can I implement this "Tasks" features for my own control?For example I want to create a...
15 Nov 2010 by Dave Kreskowiak
It's called a "Smart Tag". You can find a quick example of it here[^].
7 Jan 2011 by Diamonddrake
How to scroll a parent control with mouse wheel while child control has focus
26 Feb 2011 by Henry Minute
To achieve your aims you will probably have to write a UITypeEditor[^] and one or more ControlDesigners or one of its descendants and quite possibly one or more TypeConverters. From your description possibly an ExpandableObjectConverter[^].Here is a link to an example that uses most of these.[^]
1 Apr 2011 by BobJanova
When you start from scratch by inheriting Control (or UserControl) you need to do everything yourself, including painting the text. You are not painting text in your paint handler, so no text appears. Add a line including g.DrawString in your paint handler.Correctly re-implementing a button...
15 Jul 2011 by Simon Bridge
Full code listing for a very simple but effective Colour-Combo (Color for those in America)
18 Jul 2012 by Christian Graus
No, of course not. Your web page may run on a lot of devices that are not windows. You should consider learning what the world wide web is and how it works. ASP.NET generates HTML only, that is all your browser understands. You can't use it to do anything that you can't do with HTML.
13 Mar 2013 by Sergey Alexandrovich Kryukov
Please use the event KeyPress as it gives you the character of the letters. It will preserve the system keyboard layouts, so you don't need to deal with each key separately. Use KeyDown to work with keys on lower level, such as F1, F2, etc.—SA
17 May 2013 by Mayur Panchal
I think u should handle OnPreviewKeydown event to catch 'Enter' key in user control and write your stuff there.
10 Jul 2013 by Ron Beyer
In the custom property setter, call the Invalidate() method on the control.
12 Sep 2013 by CPallini
You didn't try Google[^], did you?
27 Mar 2014 by BillWoodruff
If you are willing to do the work to create a UserControl, you can combine a ListView, which supports Groups, with a TextBox, for displaying the selected List Item. It's actually pretty easy to do, but, if you are relatively new to C# and Windows Forms, and have no experience with UserControls,...
19 May 2014 by OriginalGriff
To add to what CPallini suggests, there is also the .NET Stopwatch class[^] whihc will let you measure it as well.
1 Apr 2015 by Sergey Alexandrovich Kryukov
Before re-posting the question (or posting very much related question), you should have seriously think at my answers you already got:How to get response when click PropertyGrid,How to show values for custom property during desgin-time C# WPF?.In addition to that: as you want to "add the...
11 Dec 2015 by CHill60
Have a look at this CP article Professional C# - Graphics with GDI+[^]There is also a reference zone[^] here on CPOr there always the M$ documentation[^]
4 Jul 2019 by OriginalGriff
Because you have said it should: Window Styles - Windows applications | Microsoft Docs[^] Look at the bit you add to the style (WS_SIZEBOX).
10 Feb 2020 by OriginalGriff
You can't, not unless you create an entirely new TextBox-like control form a UserControl and allow am much, much larger-than-standard Length. But it's not a good idea, even if you could (or you go to all the effort involved in "rolling your own"...
23 Feb 2021 by Dave Kreskowiak
Add a reference to it the .DLL in the library. Right-click the References item in Solution Explorer and click "Add Reference". In the window that shows up, click Browse on the left and go find the .DLL(s) that hold the controls you want to use.
17 Jan 2010 by #realJSOP
I ended up just putting label controls where I wanted text. I don't think you can label the tick marks in the control itself without overriding it with your own control.Beyond that, the labels you want don't mean the same thing. The tick marks on a track bar control are evenly spaced and...
23 Jun 2010 by Sandeep Mewara
Well you need to override GetDesignTimeHtml method. Create a designer class for your control and override it. Have a look at this article. This has an example of how to show design time HMTL: Customizable 'Loading' Control for Web Applications with Designer Support[^]
29 Jun 2010 by AugustinJ
FOUND IT!!public override void PositionEditingControl(bool setLocation, bool setSize, System.Drawing.Rectangle cellBounds, System.Drawing.Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool...
9 Jul 2010 by Abhinav S
If you want to build your own custom template, see here.
22 Nov 2010 by RelicV
you need to convert the edit mode into normal mode by just giving the "editIndex" value as -1.Try this after you update/delete/insert your recordgridview.EditIndex = -1;This should be fine..Regards,Vamsi
11 Feb 2011 by Anubhava Dimri
Localized Files information are saved in XML format in resources or etc location.So you can retrive the data from xml file and Easily to use and share it.You should manually write code for getting resources files from one project to another.
26 Feb 2011 by Sergey Alexandrovich Kryukov
This is quite possible but not easy at all; you'll to write several things to allow custom edit in the PropertyGrid. I think modal form is not a good idea as you can do much better by providing a custom in-place editor. However, a modal form is also possible: you in-line editor will be the...
29 Mar 2011 by Henry Minute
For WindowsForms take a look at this thread[^].
31 Mar 2011 by BobJanova
If you inherit from UserControl you need to do everything yourself, including managing the list of items that are in the list box. For example, here is my control to solve a similar problem.
5 Apr 2011 by Maciej Los
1) Open MS Excel2) ALT+F11 to open VBA code editor3) Add new class (menu Insert->Class module) and change it name to: ClsCalcTemp4) Copy and paste code below:Option ExplicitPrivate mdblCelsius As DoublePrivate mdblFahrenheit As DoublePrivate Sub Class_Initialize() Celsius...
3 May 2011 by JOAT-MON
One way you could accomplish this is to use the Paint() event to check the rows and if there are none, then write your message:private void dataGridView1_Paint ( object sender, PaintEventArgs e ){ DataGridView sndr = ( DataGridView )sender; if ( sndr.Rows.Count == 0 ) //
27 May 2011 by Wonde Tadesse
Take a look at Building Custom Paging with LINQ, ListView, DataPager and ObjectDataSource[^]I think it's nifty.[EDITED]1. Large Dataset Performance Demystifie[^]Mind you it is 100k, which is 4 times larger than yours.2. Linq to sql-part 3 querying our database.aspx[^]I want...
16 Jun 2011 by Sergey Alexandrovich Kryukov
By the reasons Bob correctly pointed out, right solution would be the following:Create your own radio button control, a completely custom one. Derive your class right from System.Windows.Forms.Control, override OnPaint to render its appearance depending on states, etc. Use...
14 Jul 2011 by BobJanova
I recommend that you don't create one control per file. That seems unnecessary, the list can manage all the entries and painting itself, which will save you a lot of window handles and time/memory used in creating controls. You should not need to do the display in a separate thread, it should...
2 Aug 2011 by Sergey Alexandrovich Kryukov
Just create 5 events; raise each event where your placeholders are. For example.public event System.EventHandler StartingInitialization;public event System.EventHandler StartedInitialization;//..protected override void BeginInit() { if (StartingInitialization != null)...
25 Jan 2012 by Tim Groven
Try this:return new Rectangle((this.ClientRectangle.Width / 2) - 15, this.ClientRectangle.Bottom - 30, 30, 30)They way you were doing it, the top of the new rectangle starts at the exact bottom of the first one, so when it draw, it goes below the bottom of the first, making it so you...
29 Jan 2012 by agent154
I understand how it works now... After using ILspy to decompile the source for TabControlDesigner and TabControl itself, I can see that I need to re-design my collection of Panels. Instead of using a simple ArrayList collection, I need to build a collection myself and overload the .Add() methods...
23 Feb 2012 by Sunasara Imdadhusen
I have created custom Textbox in Silverlight 4, MVVM and PRISM 4. The custom text box has dynamic behavior link it dynamically set TextMode to either Password or Text.This is working perfect. ( if i am bind TextMode static)
23 Feb 2012 by Sunasara Imdadhusen
Hi All,I resolved this issue using following code, I have changed PasswordTextBox class TextMode property.public Mode TextMode{ get { return _TextMode; } set { _TextMode = value; }}Topublic Mode TextMode{ get { return (Mode) GetValue(TextModeProperty); } set {...
26 Mar 2012 by Ewert Bergh
An easier way to do this is to import System.Windows.Controls.Primitives and use the VisualTreeHelper Extensions GetVisualDescendants or GetVisualAncestors!e.g.:protected override OnApplyTemplate(){ base.OnApplyTemplate(); Border bor = GetVisualDescendants() ...
5 Jun 2012 by Sergey Alexandrovich Kryukov
Please see my comment to the answer by OriginalGriff. Never use SendKeys for such things. You can use System.Windows.Forms.Control.SelectNextControl, or System.Windows.Forms.Control.GetNextControl in combination with System.Windows.Forms.Control.Focus. Please...
10 Oct 2012 by Sergey Alexandrovich Kryukov
This is not how property grid works and customized. You don't show or hide the grid features, you change the data model. The idea is: you assign SelectedObject property of the PropertyGrid, and it presents your object. How to customize it: you use some different object, which only represents...
27 Oct 2012 by OriginalGriff
Mouse Hover is a slow event - it has to be because it is only triggered after the mouse has been stationary over the object for a small period of time.It you want an immediate effect, then you need to look at the MouseEnter and MouseLeave events instead!
14 Feb 2013 by Sergey Alexandrovich Kryukov
Call Invalidate on size changed. That will solve your problem.Whenever you need re-rendering and ultimately calling you paint handler, you call one of the Invalidate methods. Pay attention that two of those method allows your to invalidate only a part of the scene (Rectangle or Region),...
4 Mar 2013 by Sergey Alexandrovich Kryukov
You live too many unknown detail of functionality. I'll try to go in a most general way.You probably need to have two modes of the same control. One is something like ListBox, but probably is extended, so you may want to use the System.Windows.Forms.ListBox functionality, or create some...
29 May 2013 by Clifford Nelson
I created a control that is a simple class derived from a ToggleButton that controls the color of the Background and Foreground depending on values of the DataContext. It works find when directly used, but I get an exception when this is used in an XML resource dictionary: Cannot create...
29 May 2013 by Irina Pykhova
this one says that you might use incorrect Build Action
4 Nov 2013 by sushil_gupta
I solved the problem. Below is the sample code. columns.Bound(a => a.Flag).ClientTemplate( "# if(Flag == 'Value1') { #" + " class='info k-button k-button- icontext' onclick='clickhere(#=parameter1#)' value='ClickHere' />" + "# } else { #" + "NormalText" + ...
22 Feb 2014 by Ravi Bhavnani
See this[^] CodeProject article for a starting point on how to do this. This example demonstrates how to add a ComboBox to a node, which you can extend to other types of controls./ravi
14 Oct 2014 by OriginalGriff
It should be in the designer source files, unless you have moved the InitilizeComponent method into your own code - that is (as Richard says) standard framework initialization code which is normally in the "MyForm.designer.vb" file - except in very early versions of VS for .NET (IIRC) which...
12 Aug 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
See Your First ASP.NET Custom Control[^] and get yourself started.
8 Feb 2016 by Kevin Marois
Take a look at this[^].It shows how to do DragDrop and Zoom.
19 Jun 2017 by David Fine
Using Attached DependencyProperty to prevent closing of Popup embedded in ToggleButton
27 May 2018 by Simos Sigma
I got an easy solution on my question here at stackoverflow.com. --- Reza Aghaei: If you are going to add some custom verbs to designer of a Form, you need to create a new custom Designer by deriving from DocumentDesigner and overriding a lot of properties and method to recreate FormDesigner. As...
11 Feb 2020 by Dave Kreskowiak
Why would you want to do this? The existing MaxLength of the TextBox also reflects the actual maximum length of a string in bytes. You can't make a MaxLength property larger and have it work. You can't create a string bigger than Int32.MaxValue...
1 Apr 2020 by Vassili Kravtchenko-Berejnoi
A generic workaround for auto-generating multiple custom columns in a WPF DataGrid in case where the data class has multiple properties of the same type
6 Mar 2024 by Graeme_Grant
List is not a bindable collection. You need to use the ObservableCollection Class (System.Collections.ObjectModel) | Microsoft Learn[^]. Here is a working solution for a similar question. Create a new project and add this code: 1. Classes: ...
28 Dec 2009 by Indrajeet Sutar
Hi, I want to create a custom text box control. i want to add required filed validator into that. when i set isRequired property to "true". then the text box must be required and vice-verca.Please tell me how to create custom control...Indrajeet Sutar
26 Dec 2009 by Abhinav S
One way to do this would be to inherit the text box control class and then add your field validator logic in that class.
27 Dec 2009 by pummychouhan
i want to add a countdown timer on web page and at runtime put my database's field value in it like i have a table Start_time and End_time in db and at code i want to display a countdown if that page open between start date and end date and time shows the left time and decrease by the time...
27 Dec 2009 by Pranay Rana
Go through following link will help you :http://www.asp.net/ajax/documentation/live/tutorials/IntroToTimerControl.aspx[^]
5 Feb 2010 by Member 645156
I have a WPF Custom Control inherited from Button.How do I programatically get the custom control to capture the Click Event (so that I can record the action and do some internal work)(basically I want to catch the event and set a certain property to a certain value) and make this part of...
5 Feb 2010 by Member 645156
SolvedI have realised why I had a problem.I could not see the Click eventThis was because I was not explicit enought in my class declaration:I put public class StateButton : Buttonobviously picked the wrong button public class StateButton :...
20 Feb 2010 by Vahid Rassouli
Hello everybody,I'm developing a custom control containing a TreeView control and a couple of buttons and etc ...Now, the question is that how can I show the smart tags menu of the TreeView at the design time?
1 Apr 2010 by zhonglin.liang
There are many buttons in a dialog. Add thick rectangle border around the button after it is pressed and hide thick rectangle border after the button is pressed again. After I pressed many buttons ,the buttons that is pressed are of thick rectangle border until I pressed them again. How to...
2 Apr 2010 by Gary Stafford
If you are asking this in regards to web-based solution, then using jQuery would make this fairly easy by switching the button's CSS classes.
2 Apr 2010 by D_code_writer
To whom it may concern,Guys I have a bit of a curious problem. I've had a custom control I've been using to edit text entries. I have implemented this using the Custom Control in the dialog toolbox, and then placing reference to my control. I have found this to be not a problem in dialogs,...
27 Sep 2018 by teolazza
I, I've created a component with a collection of controls as property:[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public List ControlsToNotTranslateThen I've created an UserControl, added some controls to it: buttons and labels.Now I...
12 May 2010 by OmiAshish
i want to build a ComboBox Custom Control. in which after selection or entry its detail portion to be display in Datagridview so that user can select with grid with detail information. and after selection datagridview visibility get false.The Problem is that in Custom Control the value...
12 May 2010 by Christian Graus
Fix your code. What else can we say ? Did you consider posting your code so we can see your mistakes ?
27 May 2010 by Gil Goodridge
I am interested in non-modal custom (Slider, Tracker, etc.) controls. Does anyone know where I would find these (either for purchase or free)? They would need to work in my environment -- I am using a HP IPAQ 210 with WM6, Visual Studio 2008, C++/MFC.
27 May 2010 by CPallini
Did you consider "The Ultimate Toolbox"? :)
27 May 2010 by Gil Goodridge
Thanks, I'll look into your suggestion....Gil Goodridge
31 May 2010 by Anu Koshy
Hi,I have a CListCtrl. The first column of the CListCtrl has sentences, i.e. each cell of the first column has a sentence. I know that it is possible to set the color of individual cells. Is there any possible way for setting color to a specific word in the sentence contained in a single cell....
1 Jun 2010 by Radhakrishnan G.
Have you try with custom draw notification from ListCtrl.If it is difficult in custom draw you can override DrawItem()RegardsRadhakrishnan G.
14 Jun 2010 by Henry Minute
One of many[^].No idea if it's any good though. :)
22 Jun 2010 by Imran Khan Pathan
Hello friends.I am working on custom server control. I need to embed js,css and image files in control. I have added js and css file but I am facing a problem to embed images which is in css file. I have set background image in one class in css file but that image does not display when I run...
22 Jun 2010 by Arun Jacob
I think its because of the wrong image path. How you specified image path in CSS?
22 Jun 2010 by Imran Khan Pathan
image in css file. background: url(bottom.gif) no-repeat right bottom; note: images are placed in server control not in web application
23 Jun 2010 by Meron LAVIE
I am designing an ASP.NET v3.5 custom control based on CompositeControl.However, I do NOT want to create my child controls via code, but rather as embedded HTML tag elements within the CompositeControl in the ASPX page, such as: ...
9 Jul 2010 by muttleytcz
Hello, how to create own form style add-in - to get it in add new item menu (look on image)
14 Jul 2010 by helianthus87
Hello,A bit larger question this time but i hope it's only alot of code and the solution is short, simple and easy and the problem is only becouse of my temporary impairment.I need to create ItemsSource to my CustomControl. The problem is the control is using to filter records in grid view...