Borderless Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martijn Mulder

    Borderless Button

    I want my buttons to look like and behave like the 'Tools' in, for example,
    MSPaint. The border of the button is invisible, the image just 'hangs' in
    the gray background. When the mouse pointer is moved over the button, the
    border shows. Clicking the button first indents the picture and on releasing
    the mouse button the selection is visible with a dark border and a lighter
    shade of gray as background color.

    How can I achieve this?


  • David Boucherie & Co

    #2
    Re: Borderless Button

    Hey Martijn...


    If I understand correctly what you try to achieve:

    - Don't use a Button control, but a CheckBox control.

    - At design time, set the following properties:
    -- Appearance = Button
    -- FlatAppearance. BorderColor = whatever you like
    -- FlatAppearance. BorderSize = 0
    -- FlatAppearance. MouseDownBackCo lor = whatever you like
    -- FlatAppearance. MouseOverBackCo lor = whatever you like
    -- FlatStyle = Flat

    At runtime you can catch the MouseEnter and MouseLeave events if you
    like, to display a border when necessary. And catch the CheckedChanged
    event (for example) to keep the border around when the button is pressed
    (checked).


    private void checkBox1_Check edChanged( object sender, EventArgs e )
    {
    checkBox1.FlatA ppearance.Borde rSize =
    (( sender as CheckBox ).Checked ? 1 : 0);
    }

    private void checkBox1_Mouse Enter( object sender, EventArgs e )
    {
    checkBox1.FlatA ppearance.Borde rSize = 1;
    }

    private void checkBox1_Mouse Leave( object sender, EventArgs e )
    {
    checkBox1.FlatA ppearance.Borde rSize =
    ( ( sender as CheckBox ).Checked ? 1 : 0 );
    }


    Of course, you can finetune this to your liking.

    Have fun.

    David



    Martijn Mulder wrote:
    I want my buttons to look like and behave like the 'Tools' in, for example,
    MSPaint. The border of the button is invisible, the image just 'hangs' in
    the gray background. When the mouse pointer is moved over the button, the
    border shows. Clicking the button first indents the picture and on releasing
    the mouse button the selection is visible with a dark border and a lighter
    shade of gray as background color.
    >
    How can I achieve this?
    >
    >

    Comment

    • Stoitcho Goutsev \(100\)

      #3
      Re: Borderless Button

      Martijn,

      The button FlatStyle property can be set to Popup that has the behaviour you
      are after. However there is one small problem that the button shows border
      evetn when the mouse is not over it. I haven't try to work around this
      problem and I think that it might be possible removing the border. I don't
      know though.

      The behavior that you described was implemented in the old ToolBar
      component. It is still there and you can use it, but you need to install it
      manually in the toolbox. I tried it and it works as you want with the small
      problem that the 3D border that shows up when the mouse hovers over the
      button has rounded corners.


      --
      Stoitcho Goutsev (100)

      "Martijn Mulder" <i@mwrote in message
      news:4561b2b5$0 $55151$dbd4d001 @news.wanadoo.n l...
      >I want my buttons to look like and behave like the 'Tools' in, for example,
      >MSPaint. The border of the button is invisible, the image just 'hangs' in
      >the gray background. When the mouse pointer is moved over the button, the
      >border shows. Clicking the button first indents the picture and on
      >releasing the mouse button the selection is visible with a dark border and
      >a lighter shade of gray as background color.
      >
      How can I achieve this?
      >

      Comment

      Working...