# VBForums CodeBank > CodeBank - C# >  Fun little "Car stereo" display control.

## conipto

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+  :Smilie: 

Bill

----------


## RobDog888

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

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

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#.

VB Code:
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.UpdateStyles()

----------


## RobDog888

Also, it probably shouldnt scroll in design mode, only in run mode.

VB Code:
If Not DesignMode Then
    'Scroll display
Else
    'Dont scroll
End If

----------


## RobDog888

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

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

Eek.  I never see that on my machine.. it's a P4 2Ghz with 256/ram, win2K.

Bill

----------


## conipto

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

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.  :Smilie: 

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

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.  :Smilie:

----------


## conipto

> 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

I'm off to bed so I will check the new version tomorrow. Try using "Public Shadows" for the Text property.  :Wink:

----------


## RobDog888

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

"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..  :Frown:   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

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

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

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

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

In accordance with this CodeBank policy regarding attachements, the original attachment has been edited and the executable files removed.

----------


## RobDog888

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.  :Wink: 

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

> In accordance with this 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

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.

----------

