The first thing is to understand that the ListView class in .NET encapsulates the List-View common control in Windows, as do most controls in the System.Windows.Forms namespace, so doing things like this will typically required that you extend ListView, override WndProc, and handle notification messages. Some Windows programming background will be helpful. You'll also want to know how to P/Invoke native methods. You can find more information in the documentation for the DllImportAttribute in the .NET Framework SDK.
You'll have to handle the drawing of each subitem by handling the NM_CUSTOMDRAW notification message. That will give you a struct (which you'll have to create, namely the NMLVCUSTOMDRAW struct). From information in that you can adjust the starting location of your text (though you'll have to draw it yourself, though that's not hard) and then paint the icon you want next to it. You'll have to figure out how to store that image information, though, be it an index into an ImageList or an Image itself. You could extend ListViewSubItem although you'll have to worry about casting each time.
Note that this may sound like a lot of work (and I'll admit it's not trivial) but it sure beats making your own list view control from scratch! There's a heck of a lot more to worry about than this. In the grand scheme of things, this approach is easy.
If you reply to this, I can send you some old source that shows some examples of owner-drawing. Though not specific to your requirements, it should give you some insight.
I have this little problem which is of pure cosmetic nature, so it doesn't really affect the application, but it would be something I'd really like to have. I searched around and couldn't find a solution for this anywhere, so I hope somebody in here knows the trick. The problem does also apply to any other .NET application, but since my application is written in C#, I post it here first:
My appplication has a nice application icon and opens several windows, which also all have this application icon. Everything looks fine in the windows taskbar, until the moment when the taskbar grouping function of WinXP kicks in. Then the group icon for my application suddenly is the default empty application icon, and the group button itself doesn't have any text, but just states the number of windows grouped, for example "3".
When I click on the group button, every item in the list has the nice application icon, but it seems that the group icon comes from somewhere else, as well as the group button text. Since other applications still have their icon even when the windows are grouped, this property must be able to set somewhere.
I read in a newsgroup that the group icon comes from SystemIcons.Application, which in fact is the empty default windows icon that I see, but this property is read-only, so there is no way for me to confirm that this icon is really used, nor can I change it to my application icon.
In case it is still not clear what I mean to the following to reproduce the problem: Open a new .NET project (C# or VB doesn't matter) and add a second dialog, then add a function in your main dialog that opens up the second dialog when clicking a button or something like that. Edit the App.ico resource so that the icon looks different and make both your windows use this file as the application icon. Now execute the application and press that button that executes your function to open more windows until the taskbar is full and WinXP groups the icons. Then you should be able to see the effect.
In case it is still not clear, I can also post a screenshot, but for the moment I'll just hope that someone is able to understand what I mean.
Set the static property Application.SafeTopLevelCaptionFormat for the group text. As far as the icon goes, I'm frankly surprised this isn't working correctly since Windows should be using the top-level form's icon. The only thing I can think of is to make sure you're using the Application.Run static method to launch your main form.
Easy - an array is a valid source for a repeater ( and that's all you need here, so why use anything heavier ? ), so store the index you're up to in viewstate, then grab the array you need from the array of arrays and make it the data source for a repeater.
Ooops - forget that if you're not doing a web page. Instead, just pass the arrays to a datagrid.
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
privateint currentIndex = -1; // before the start of the array
In your button click event handler:
if (currentIndex==5) // Don't run off the end of the array
currentIndex = 0; // Reset to the start// Build the label text
StringBuilder sb = new StringBuilder();
for(int i=0; i<9; i++)
labDisp.Text = sb.ToString();
I'm assuming your array is called "arrayObject" since you didn't mention it anywhere.
switch( keyData )
bIsInputKey = base.IsInputKey(keyData);
This does not appear to work, I have set keypreview on the form to true, that does not help.
I have tried this code in a dummy app and it works fine, and I have placed a break in the above code to see if the override is ever run - it isn't. There must be something in the rest of the code or a property that is stopping this.
Does anyone have any suggestions???? I am new to C# and have banged my head against the wall all day on this one!!!
I want to have a floating window in my app. One that is always on top of the main window...
But, if I make a form and set the TopMost property to true, the window is also on top of every other application.
I mean, when working in my app it works fine, but if i open another app in front of it, my floating window is also on top of that app... Not good...
"When a form is owned by another form, it is minimized and closed with the owner form. For example, if Form2 is owned by form Form1, if Form1 is closed or minimized, Form2 is also closed or minimized. Owned forms are also never displayed behind their owner form. You can use owned forms for windows such as find and replace windows, which should not be displayed behind the owner form when the owner form is selected."
The parent and the owner are too different things. Besides, to set the owner you use the Form.Owner property on the form that should be owned. The Form.OwnedForms property is a read-only property that is a Form array. Even replacing an element in the array won't set the Form.Owner property of the form you want owned.
Setting Form.Parent (inheritted from Control) won't solve this problem. Instead, set Form.Owner of the floating windows to the Form they should always overlap. See the documentation for Form.Owner in the .NET Framework SDK for more details.
Hello everyone, really struggling here......Can someone clear up a few issues for an inexperienced C# student...I need to implement a precise timer (ie not the ones supplied invisual studio.net)I need the timer component to act 1) like the .Net timers available ie. i set a time say 2 seconds and when this time has a elapsed an event is raised? 2) the elapsed time that raises an event may be less than 1 second that is something like miliseconds. 3)i implement several of these timers in one single application (perhaps using threads)?
Basically I am communicating serially with another computer (was quite difficult using C# until I discovered somewhere that you can use the MSCOMM control)... and I need to set up several timeouts. For instance I send several messages to the other computer and for each message I expect a reply in a certain amount of time. So I send a message and then I want to start a timer... when a certain amount of time elapses say 500 milliseconds then i want an event to be raised as a visual studio timer would do..... If anybody has any comments advice snippets of code with a little explanation or even other sources of help .... i would be truly grateful!
What's wrong with System.Threading.Timer? The TimerCallback is executed in a separate thread which is one of your requirements. For even more accuracy (according to the .NET Framework SDK), you can use a server-based timer like System.Timers.Timer.
If you want to use native function, you have to P/Invoke it and worry about marshaling parameters (depending on the native function called). The very act of marshaling could degrade accuracy over time, whereas the System.Threading.Timer is internally managed by the CLR. The other two call CreateWaitableTimer. So, basically, either you P/Invoke the methods or use the timers that do, or use System.Threading.Timer which should be about as accurate as you can get with the class library since it's managed internally by the CLR.