|
-
Jun 21st, 2005, 10:40 AM
#1
Thread Starter
Addicted Member
Extract graphics object of listview control
Hi,
I am trying to extract the graphics object of a listview control. It is quite a simple project - I am populating a listView control with some data from a database and I would like to show some custom text in the center of the "whitespace" of the listview that says "please wait" or some other helpful comment to my user!!! I have tried the following
Code:
Graphics g = Graphics.FromHwnd(listView1.Handle);
g.DrawText(.... code in here ... );
g.Dispose();
The above code does not error but it doesnt draw on the object... please can somebody help?! I saw somewhere that you can use a "SetStyles" method to allow on paint events but I can't seem to find enough to help me out - can anybody please help?
Kind regards,
DJ
-
Jun 21st, 2005, 11:18 AM
#2
Re: Extract graphics object of listview control
Sounds like you are complicating matters unnecessarily. Why not just place a Label with the appropriate BackColor over the ListView for the short period while the data is loading?
-
Jun 22nd, 2005, 02:08 AM
#3
Thread Starter
Addicted Member
Re: Extract graphics object of listview control
 Originally Posted by jmcilhinney
Sounds like you are complicating matters unnecessarily. Why not just place a Label with the appropriate BackColor over the ListView for the short period while the data is loading?
How can you call three lines of code complicated?! It is probably less than creating a label. Anyway..... I do see your point and this solution would possibly work however I know there is a way to do this and would like to know the correct way to achieve the desired result.
Thanks,
DJ
-
Jun 22nd, 2005, 02:25 AM
#4
Re: Extract graphics object of listview control
 Originally Posted by DJ_Catboy
How can you call three lines of code complicated?! It is probably less than creating a label. Anyway..... I do see your point and this solution would possibly work however I know there is a way to do this and would like to know the correct way to achieve the desired result.
Thanks,
DJ
Quite right, you are. The question I was really asking was "why look for a more obscure solution when there is an obvious one right in front of you". Who's to say which is the "correct" way? I guess learning this now does arm you for the future when you may need that method, though. I apologise in advance to the GDI+ aficionados for calling it obscure.
-
Jun 22nd, 2005, 02:41 AM
#5
Re: Extract graphics object of listview control
Unless I'm mistaken, you will need code similar to this:
VB Code:
Dim g As Drawing.Graphics = Drawing.Graphics.FromHwnd(Me.ListView1.Handle)
Dim f As Font
Dim b As Brush
Dim x As Integer
Dim y As Integer
g.DrawString("Please wait...", f, b, x, y)
g.Dispose()
You will have to create the font and brush yourself. The (slightly) complicated bit is working out x and y to get the text centred. You will probably have to use Graphics.MeasureString to determine the size of the text drawn with your chosen font.
-
Jun 22nd, 2005, 02:44 AM
#6
Thread Starter
Addicted Member
Re: Extract graphics object of listview control
Hi,
Yeah that is what I have been experimenting with - however it would appear that the handle is not giving me the actual "whitespace" where the ListViewItems go - it is giving me the overall container - therefore when I draw on that it is being printed under another object...?! After discovering this your idea of using the label sounds better and better.....! Thanks for the help....
DJ
-
Jun 22nd, 2005, 09:30 PM
#7
Re: Extract graphics object of listview control
If you still want to go your original route, you may (I haven't tested) find that Me.ListView1.CreateGraphics() gives you what you want.
-
Jun 23rd, 2005, 02:10 AM
#8
Thread Starter
Addicted Member
Re: Extract graphics object of listview control
Hi,
I also found this method but I think it returns the same as the previous example - i.e. you get the graphics method of the underlying object and not the stuff on top of it. I have actually got around this problem in two ways: firstly i have added a label over the top of the control (it does look nice but...) and secondly I have made my "long operation" take a fraction of the time so now updating the user is not as important.
However I am a purist and would really like to know if it is possible from somebody?!
Many thanks for all of the help,
DJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|