Jump to content
Xtreme .Net Talk

Cags

Avatar/Signature
  • Posts

    699
  • Joined

  • Last visited

Everything posted by Cags

  1. It depends on how you look at it as to whether the problem is the border or the region. The fact is you are using the same calculation to work out both, which means the border is drawn the same size as the region however it is drawn slightly further down and across. You need to essentially work out the path of the border and the path for the region seperately which is what the code I posted before did (It certainly wasn't perfect code, but it did make some alteration to the border). At this moment in time I'm not entirely sure of the exact code that is required to make the border the correct size, but you definately have to work out the values seperately. I'll have a proper look at it tomorrow when I'm completely sober. I might eventually post the code for the test control I've been doing incase anybody else is trying to achieve the same effect.
  2. The way i've been getting a border on my test control is like this, note you will have to modify the GetPath method slightly to accept a Rectangle. With the method I'm using I'm not entirely sure the border is the right thickness but you can tweak the size of the rectangle you pass in untill this is correct. private sub CalcLayout() _BorderPath = GetPath(new Rectangle(1, 1, this.Bounds.Width, this.Bounds.Height)) Me.Region = new Region(GetPath(this.Bounds)) Invalidate(); end sub then in the OnPaint method you call DrawPath(myPen, _BorderPath); EDIT: You also nead to remember that you will have to call CalcLayout whenever the border thickness is changed, and Invalidate whenever its colour is changed etc.
  3. ahh i think its because the rectangle you pass in to the linear brush should be relative to the control not the form so it should be new Rectangle(0, 0, this.Width, this.Height)
  4. Try changing e.Graphics.FillPath(filler, graphPath) to e.Graphics.FillRegion(filler, this.Region);
  5. It will help your program run fast if you call get Path only when you resize / create the control rather than when every time you paint. Todo this create a method called CalcLayout, and add the path calculation to it something like this... (my vb isn't that good) Public graphPath As New System.Drawing.Drawing2D.GraphicsPath Private Sub CalcLayout() graphPath = Me.GetPath() If Me.ClientRectangle.Width = 0 Then rect.Width += 1 End If If Me.ClientRectangle.Height = 0 Then rect.Height += 1 End If Me.Region = graphPath Invalidate() End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) If Me._GradientMode = LinearGradientMode.None Then filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour1, System.Drawing.Drawing2D.LinearGradientMode.Vertical) Else filler = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Me._BackColour1, Me._BackColour2, CType(Me._GradientMode, System.Drawing.Drawing2D.LinearGradientMode)) End If e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias e.Graphics.FillPath(filler, graphPath) End Sub Protected Overrides Sub OnResize(ByVal e As EventArgs) MyBase.OnResize(e) CalcLayout() End Sub
  6. Ok you've confused me now. How are you drawing the actually main body colour of the control?
  7. In your OnPaint method how are you drawing the Background of the control are you calling e.Graphics.Clear(this.BackColor); or are you drawing a region/ rectangle?
  8. I'm slightly confused, the first time I read your post I thought that with a single press of escape you wanted to close several forms. But the second time I read it I just got the impression you wanted several forms with similar behaviour to each other, closing each one individually when escape is pressed. If the latter is true then as you can say this could be handled by either attaching events in the manner your doing or by inheritance. To do the inheritance method you simply create a class (called ExtendedForm or something) that inherits from System.Windows.Form and add/override key events. Then any form you wish to have this behaviour you inherit from MyNamespace.ExtendedForm rather than System.Windows.Form.
  9. My VB isn't great, but I think its this... Protected Overrides Sub OnPaintBackground(e As PaintEventArgs) 'MyBase.OnPaint(e) End Sub
  10. Is this the kind of thing you meant... http://www.codeproject.com/csharp/PropertyGrid.asp
  11. The most likely cause of the flicker is the OnPaintBackground event which fires before the OnPaint event. Using C# this can easily be solved by doing the following section of code. It is worth noting however that if you do override this method you must draw the entirity of the control (using either Graphics.Clear(), or another method such as DrawRectangle()) in the Paint method otherwise some sections will not get drawn protected override void OnPaintBackground(PaintEventArgs pevent) { //base.OnPaintBackground (pevent); } With regards to the Invalidate() method all this really does is tells a control to redraw to the screen. When used in conjunction with a bitmap buffer this can reduce the amount of calculations that are performed by the Paint event.
  12. Hard to say without knowing what code your application performs. As a side note however most applications aren't distributed as the compiled exe, but instead are wrapped into a deployment package which can be istalled on the target pc. I'm assuming this isn't what you did?
  13. Add a public method (PopulateField etc.) to the first form that is passed the data as a parameter. Then this method can be called from the search field. Creating the second form as a Dialog with the first form as its parent may also help make this easier.
  14. After another look at your code I would also suggest trying to eliminate the Try Statements as they shouldn't be neccessary in this case. If you store the path of the border locally it will prevent you having to call GetPath everytime you paint, instead calling it only when the control is resized.
  15. Well I thought I might reply now, just incase you have chance to look at this before I'm available to check more closely tomorrow. If my post doesn't make sense I appologise, I have been drinking. As I'm only looking at sections of your code it's hard to tell, but I notice that in your Render method you are attempting to draw a local bitmap to your screen. Does this mean that all drawing is done to a local bitmap and then the paint method simply draws the local bitmap? If this is the case then an application witch uses alot of instances of this control could use a lot of memory. I suppose this might cause some slowdown. I can see no particular reason why the basic code behind drawing a curved rectangle should cause a slowdown in your application. I will look at your code further tomorrow, but if you could give me an approximation of how many of this control may be on screen at once, then that would be very helpfull. EDIT: I nearly forgot to mention, you say your entire controls doesn't draw correctly, I could be wrong but i'm guessing by this you mean part of the border is missing. If this is the case it is perhaps because you are setting the region of the control to the size of the border, wheras infact this region should be large enough to entirely encase the border (i.e at least 2 pixel larger in either direction).
  16. No it will not need the onPaintBackground as the control only draws what is within the region and yes the region is made up of the 4 lines and 4 corners that make the shape of your control.
  17. Setting the Region setting seems to be the best solution, I just gave it a quick test. Create a region using a graphics path (if your not already doing that), if you are just set this.Region = new Region(myGraphicsPath), you will need to make this calculation everytime you resize the control etc but it should work fine.
  18. I'm sure the method I outlined is probably your best solution, but I can't really say for sure untill i've tested it as a designtime control (which i don't know how todo) so i'll have a look into that and get back to you.
  19. I'm assuming you mean you want a progress bar that looks like the one you see when Windows XP is loading. As far as I'm aware there isn't one included with .Net you would either have to create a custom control or find one made by a 3rd party.
  20. Maybe I'm missing the point here, but that surely doesn't help at all, and is infact quite likely to be the method Pselus is using. The links you provide basically talk about drawing a rounded rectangle. Pselus control already does that. The problem is it's being drawn onto a square control and what Pselus wants is the areas its not being drawn on to show whatever is behind the control.
  21. It's going to be incredibly hard to be any more helpfull without seeing more code as there are many variables that may be causing you trouble, are you calling the main draw code from the paint event or from other events (which cause changes). Are you drawing directly to screen or to some kind of memory buffer? On a side note I assume you haven't accidently caused a loop by calling InvalidateEx from the OnPaint Event?
  22. Maybe this will help... http://www.bobpowell.net/transcontrols.htm
  23. I'm glad you fixed the problem but I just thought I'd mention that by the sound of your problem a try catch statement is not the ideal method of solving it.
  24. Just because a single program happens to open the file it doesn't make it the correct/standard format and as such you will struggle to get other programs to open the file.
  25. Hmm... that is very odd indeed, but it's not only VB that can't load it properly, if I save that image to my desktop then double click on it, a blank square is displayed. So my Windows XP SP2 can't see it properly either.
×
×
  • Create New...