473,761 Members | 3,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to start writing custom control?

Hi,

I need to develop a custom control. The control is going to be something
like Properties window in VS - listview (grid?) with resizable columns and
collapsable sections.
The control needs to be read-only, so I do not need embeded text/listboxes,
but I need pictures and some more features. So I started to extend ListView
control. First I tried to do custom item selection (pseudo-code):

ListView:
protected override void WndProc(ref System.Windows. Forms.Message m) {
base.WndProc(re f m);
if (m.Msg == WindowMessages. PAINT)
for(int i = 0; i < this.items.Coun t; i++)
if (this.items[i].Selected)
(this.items[i]).DrawSelected( );
}

ListViewItem:
public void DrawSelected() {
Rectangle itemRect = GetBounds(ItemB oundsPortion.It emOnly);
Graphics g = Graphics.FromHw nd(base.ListVie w.Handle);
g.DrawRectangle (new Pen(Color.Red), itemRect);
g.FillRectangle (new SolidBrush(Colo r.Silver),
itemRect.X + 1, itemRect.Y + 1, itemRect.Width - 2,
itemRect.Height - 2);
g.DrawString(th is.Text, this.Font, new SolidBrush(Colo r.Black),
itemRect);
g.Dispose();
}

However, this work is 'try and guess' - strange effects appear like:
- moved text (probably it should be painted one pixel right, but why?)
- unselected items (painted by base.WndProc) have some unerased silver
background (probably FillRectangle is too large)
and so on

So the questions are:
- which Message(s) should I implement?
- how to use Rectangle(s)?
- which items should be painted? all, visible (how to check?)
- what about partially-hidden items?
- where to write texts?
- should I use base.WndProc; where?
- what is 'Erase Background' message? what is a [whatever] message?
- what about efficiency of WndProc? seems it should be fast
- and much more

I found: http://www.codeproject.com/cs/miscctrl/ . But it is not a good
point to start as some examples are complicated and poor documented. I need
a good article and in-depth explanation to start with. Just can't find one.

Regards.

Mar 14 '06 #1
0 1339

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11893
by: Nick Haines | last post by:
I need to write my own custom text edit control.. but I'm not sure where to start - I've never written a custom control... the features I want are somewhat similar to the VS .Net text editor - text colouring, collapsible regions etc... I haven't been able to find anything that could achieve that which is free... So what is the suggested starting point? Can I make some kind of control that derives from a RichEdit box and write my own...
1
4351
by: Suman | last post by:
We are facing a problem with a Service we developed. It does not start after a re-boot. We can Start/Stop the service from the interfacing Application and the Services Control Panel all day long. But it does not start after a reboot. Details We have implemented the Service using CAtlServiceModuleT (ATL 7.0). For initialization and un-initialization, we have overridden the PreMessageLoop and the PostMessageLoop. In the initialization...
0
1766
by: spacehopper_man | last post by:
hi - I am writing a "tab" control. - but it's losing the viewstate of the content pane when I switch between tabs. can anyone shed any light on why I'm losing ViewState based on my simple example below? - if I put the tabs at the top of the screen viewstate is lost -
4
1770
by: Smokey Grindle | last post by:
What is the best way to write dynamic controls in ASP.NET 2.0?
3
1155
by: shapper | last post by:
Hello, I am starting to create various custom controls for Asp.Net 2.0 and I am using Visual Studio 2005. I have a few questions: 1. Should I use the Web Site or Project Model? I believe Project Model allows me to embed the resources (images, css files, etc) into my DLL.
15
6521
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
4
1300
by: mortb | last post by:
Hi! I have a really large and complex table. The table may consist of several thousand rows. When I render the table with asp.net web controls the control won't stream out to the browser before the appending of rows is completed. The table is created in a custom web control. I know I can use Response.Write to directly output to the client, but I'd like to know if there is another way.
1
1081
by: Brock | last post by:
What does the "I" at the start of some terms signify? Examples: INamingContainer, IComparable Also what are some of the most common examples and their use?
2
974
balabaster
by: balabaster | last post by:
I've got a composite custom control that I've bound to a data object. All works find - but when I modify the data in the data object that is bound - how do I get my custom control to re-read from the master data source? I know I run DataBind() to get it to rebuild from the data source, but the data held inside the control is still the old data unless I set the data source again: i.e. MyControl.DataSource = MasterData...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.