Appearance

How would I change the appearance of some controls in the windows form, such as turning the tabs color from the normal color to say a gradient green to white or change the buttons shape and color from a rectangle to a circle and the color from a solid to a gradient. That kind of thing.


Answer this question

Appearance

  • sdoc

    Wow, I appreciate that a lot. Except when I put the first code in button3_Paint, it changed the form's appearance instead of the button's appearance, because of the "this.ClientRectangle" thing. Not to sound like a total noob, but I am new at GDI+ and the whole designing thing, so if you could maybe explain to me about the button class, like what I should put in there, where I should start because I honestly don't have a clue what to put in the new class.



  • fripper

  • Jabs

    I understand what u r saying but could u give me a working example

  • jaegd

    I just tried something else to see if it would work, I tried changing "this.ClientRectangle" to "button1.ClientRectangle" and when I ran it, it turned the whole form into a little button shaped taskbar, it totally psyched out, you'd have to run the code to understand what I'm talking about. It was the weirdest thing I've ever seen. Run the Code!!!

  • Tery Emilson

    HI sniper,

    Sorry for being late is helping you out.I was out of station for a couple of days.

    By the example what I meant was just to give an illustration of using garphics path.You have to modify it according as per your need .The sample code posted is for carving the top corners of a big GUI for example a form .The diamter of the arc which is given is in conjuction with that form.So if you application's client rect is very small,that value has to be varied..(obviously it has to be small).

    Regarding the this.ClientRectangle;this denotes the class whose edges have to be carved.That means our implementation has to be in the class whose edges has to be carved.For that you can make a button by deriving from System.Windows.Forms.button class an implement the logic inside that.Hopes that this helps you


  • gooon

    Which part of buttons are you trying to change If you're trying to modify something small you could derive a class from ButtonBase and work from there.

  • cracklestudios

    For making a button round,make your own button class deriving from Button,you can then carve the edges to appropriate shape using Graphices path.

    Example for carving using graphics path.This example wille be providing the carving at the top left and right corners

    Rectangle rect = this.ClientRectangle;

    using (GraphicsPath path = new GraphicsPath ())

    {

    const int diameter = 20;

    Rectangle arcRect = new Rectangle (rect.Location, new Size (diameter, diameter));

    path.AddArc (arcRect, 180, 90);

    arcRect.X = rect.Right - diameter;

    path.AddArc (arcRect, 270, 90);

    arcRect.X = rect.Right- diameter;

    arcRect.Y = rect.Height - diameter-1;//One is added to produce the fineness at bottom right corner

    path.AddArc(arcRect,360,90);

    arcRect.X = rect.X ;

    arcRect.Y = rect.Height - diameter;

    path.AddArc(arcRect,90,90);

    path.CloseFigure ();

    Region = new Region (path);

    }

    You can give little bit of shining effect drawing using colour blendnig.

    The following code snippet is a simple example for colour blending

    System.Drawing.Drawing2D.ColorBlend clrBlend = new ColorBlend();

    Color []clrs = { this.ForeColor,Color.White,this.ForeColor,this.ForeColor,this.ForeColor};

    float []flts = { 0.0f,0.3f,0.6f,0.7f,1.0f } ;

    clrBlend.Colors = clrs;

    clrBlend.Positions = flts;

    Brush.InterpolationColors = clrBlend;

    g.FillRectangle(Brush,0,0,this.Width,this.Height);

    The other approach is to make use of an image of a curved button.You can make the button to have transparent back ground so that the button seems to be a curved one.


  • tall_matt

    Thank You for showing me that article, I learned a lot from it when it comes to GDI+, however it did not tell me how to change buttons or other controls.

  • Rafael Mores

    Stuff like, I want the button to be a circle and also be a gradient from different hues of blue, and I was wondering if I could add reflection to the button like from a light shining off of the front, and I also wanted to know if it would just be better if I got a good photo program such as Photoshop and made small pics of the shapes and color that I want and just add like click functionality to the image. I don't know if you know, but do you know about WMP 11 yet, I have it and I like the graphics on it a lot and the play button on there, I like it the best out of all of the graphics, like the gradients on it and the reflection and how when the mouse hovers over it, it glows a blue ring around it. That kind of thing. Do you know whether or not if the play button is an actual button that Microsoft just changed the appearance of or just a clickable image or what

  • Tom Lichtenstein

    "this" in the line "Rectangle rect = this.ClientRectangle;" is refering to Form1 therfore carving off the two upper corners in the form rather than the button. Which I am a little bit confused in because I put the whole first block of code that you gave me in the function "Button1_Paint" so it shouldn't be doing that, correct

  • Mainiac007

    You will have to handle the Paint event or override the OnPaint method (in the case of subclassing).

    You can then use utility methods in the System.Windows.Forms.ControlPaint class to perform drawing and retrieval of colors to match how the currently running version of Windows draws certain aspects of the controls (like DrawBorder() and Dark()).



  • Appearance