PDA

Click to See Complete Forum and Search --> : Fun little "Car stereo" display control.


conipto
Nov 12th, 2005, 11:46 PM
Hey, I made this for a media player for my girlfriend (one that's a bit faster to load than WMP, since she has to be able to fire it up on the spot when she hears noises coming from the bathroom!) But I thought I'd share it to see if anyone had any big improvements, suggestions, etc.. so that I can make it a little more reusable.

Attatched solution contains sample project and the control library/code.

Big thanks to those in the Graphics forum who helped me figure out my rusty GDI+ :)

Bill

RobDog888
Nov 13th, 2005, 12:08 AM
Very nice but it scrolls a bit jagged when you use 9 or 10 as the interval. I can only suggest so far after my initial look is that you may be running rundant loops drawing the scrolling text. The RefreshDisplay is called and it does the same thing that the OnPaint does. perhaps doing a .Invalidate would suffice since it will invalidate the region and force an OnPaint anyways. The way you have it now it refreshedisplay and causing an additional onpaint.

conipto
Nov 13th, 2005, 12:18 AM
Originally invalidate was how I had done it, but it looked awful, since it was drawing the background as well, the whole thing was all flashy the whole time..

Bill

RobDog888
Nov 13th, 2005, 12:30 AM
Oh thats right. You could add a backbuffer when creating your graphics to eliminate the flicker. This is VB.NET but it should be simple to change to C#.
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()

RobDog888
Nov 13th, 2005, 12:34 AM
Also, it probably shouldnt scroll in design mode, only in run mode.
If Not DesignMode Then
'Scroll display
Else
'Dont scroll
End If

RobDog888
Nov 13th, 2005, 12:50 AM
I think all the loops may be slowing you down too. Maybe looking at the logic a bit to see where we can improve. This is what I saw when I had the speed at 10. There must be a way to increase performance...

conipto
Nov 13th, 2005, 01:11 AM
Thanks for the tips! Those were all easy to implement and did make a difference in how it looks. The DesignMode is good to know, because that was ticking me off if I made a looping error and it crashed all of VS.

Code updated

Bill

conipto
Nov 13th, 2005, 01:13 AM
Eek. I never see that on my machine.. it's a P4 2Ghz with 256/ram, win2K.

Bill

conipto
Nov 13th, 2005, 01:17 AM
I modifed the OnPaint method to not draw the grid unless it's in design mode (since it gets drawn .25 seconds after the program starts anyways.) That might cut some redundancy out of the loops.

Bill

RobDog888
Nov 13th, 2005, 01:21 AM
Yes, it seems to handle a little longer of a string and a little smoother scroll but still I'm curious to figure it out. :)

How about adding a Text property to the UC so you can at least see the static text its going to scroll in Design Mode? Add it next to the Color and ScrollSpeed?

Also, how about instead of trying to figure out which squares to draw gray and which to draw in the property color in loops and arrays, you just blank out all the squares with gray and draw the lines and then do the .DrawString? You may have to draw the gray lines again but that should still save you valuable processing time not having to loop several times.

RobDog888
Nov 13th, 2005, 01:24 AM
I'm running a P$ 2.8 Hyper Threading system with 1 Gig of dual channel DDR RAM with dual RAID SATA drives. I just let it run a minute or so with the speed of 10 and it got all wiggy on me. :)

conipto
Nov 13th, 2005, 01:40 AM
Yes, it seems to handle a little longer of a string and a little smoother scroll but still I'm curious to figure it out. :)

How about adding a Text property to the UC so you can at least see the static text its going to scroll in Design Mode? Add it next to the Color and ScrollSpeed?

Also, how about instead of trying to figure out which squares to draw gray and which to draw in the property color in loops and arrays, you just blank out all the squares with gray and draw the lines and then do the .DrawString? You may have to draw the gray lines again but that should still save you valuable processing time not having to loop several times.

Try it now, I did change one thing that made a big difference. I am drawing on the refresh to a bitmap in memory, then once it's updated, it's only drawing to the screen once with a Graphics.DrawImage instead of all the FillRectangles. I also made the graphics objects global so they aren't disposing and initializing every time.

P.s. - It has a text property. How can I get the text property to show in the designer? I tried new, override, etc, and it never shows up. Font worked out ok, but why not Text?

Bill

RobDog888
Nov 13th, 2005, 02:01 AM
I'm off to bed so I will check the new version tomorrow. Try using "Public Shadows" for the Text property. ;)

RobDog888
Nov 13th, 2005, 11:54 PM
In VB.NET we have the Shadows but in C# there is no Shadows. Unless someone knows a way what about renaming it to something that does not conflict withthe Text property?

conipto
Nov 13th, 2005, 11:57 PM
"new" is basically the equivalent to "Shadows" as far as I could tell in the book I have. I did try that, but it didn't work.. So for a while it was DisplayText.. but then in the intellisense both show up, and that was confusing.. :( The text property does work though, I just can't figure out how to make it show in the designer..

How about the flicker, gone?

Bill

RobDog888
Nov 14th, 2005, 12:00 AM
Yes, the flicker is gone and the scrtolling is 100% improved.

Isnt there Attributes in C# too?

No crashing for me and the Color and ScrollSpeed are coming up as errors that they are not properties (always came up this way)

RobDog888
Nov 14th, 2005, 12:18 AM
I found the way to place attributes for C# but I think there are a couple of issue to solve first. The Color property should be Forecolor and we could rename Text property to ScrollText property?

RobDog888
Nov 14th, 2005, 12:48 AM
Here are a few improvements to the Properties and other stuff.
I added the property Attributes to place them in the proper category and added a description too.

conipto
Nov 14th, 2005, 03:19 AM
Wow, thanks for showing me that. It was I admit driving me nuts having all my properties displaying at the bottom. Well, with your slight improvements on the properties, and now that I've got the graphics wrapped up, it's all wrapped up. Anyone that wants to use it, DL Rob's version for easier properties.

One thing - I am curious why you couldn't see the properties for scrollspeed and color - Those two never gave me any problems..aside from being all the way at the bottom.

Bill

Hack
Nov 14th, 2005, 07:00 AM
In accordance with this (http://www.vbforums.com/showthread.php?t=337255) CodeBank policy regarding attachements, the original attachment has been edited and the executable files removed.

RobDog888
Nov 14th, 2005, 01:54 PM
Yes, with .NET project attachments its always a space saver too to remove the exe. Maybe you can add a link on your first post to the updated attachment of mine of just update your attachment. ;)

Bill, I couldnt get it to "crash" and the property errors were appearant when I rebuilt the solution. I think its a naming conflict with the class name and the property name?

conipto
Nov 14th, 2005, 03:17 PM
In accordance with this (http://www.vbforums.com/showthread.php?t=337255) CodeBank policy regarding attachements, the original attachment has been edited and the executable files removed.

Ah, crap.. I normally just uncheck recursive zipping, but with two projects in the zip I left it checked. My apologies.

Bill

RobDog888
Nov 14th, 2005, 03:35 PM
All I do is delete the Bin and Obj folders but not the obj for the lib because that gives issues when your opening your solution.