Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just make a new image and paste the original one at an offset. Then set that as the <code>Button</code>'s <code>Image</code>.</p> <p>Example:</p> <pre><code>private void button1_MouseDown(object sender, MouseEventArgs e) { // replace "button_image.png" with the filename of the image you are using Image normalImage = Image.FromFile("button_image.png"); Image mouseDownImage = new Bitmap(normalImage.Width + 1, normalImage.Height + 1); Graphics g = Graphics.FromImage(mouseDownImage); // this will draw the normal image at an offset on mouseDownImage g.DrawImage(normalImage, 1, 1); // offset is one pixel each for x and y // clean up g.Dispose(); button1.Image = mouseDownImage; } private void button1_MouseUp(object sender, MouseEventArgs e) { // reset image to the normal one button1.Image = Image.FromFile("button_image.png"); } </code></pre> <p><strong>EDIT</strong>: The following function fixes a problem where the image would not 'pop' back up when the cursor leaves the button area while the mouse button is still pressed (see Labor's comment below):</p> <pre><code>private void button1_MouseMove(object sender, MouseEventArgs e) { Point relMousePos = e.Location; bool mouseOverButton = true; mouseOverButton &amp;= relMousePos.X &gt; 0; mouseOverButton &amp;= relMousePos.X &lt; button1.Width; mouseOverButton &amp;= relMousePos.Y &gt; 0; mouseOverButton &amp;= relMousePos.Y &lt; button1.Height; if (mouseOverButton != MouseButtons.None) { button1_MouseDown(sender, e); } else { button1_MouseUp(sender, e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload