Remove all extra space around a button with an image? - winforms

Alright, try as I might, I cannot for the life of me get rid of this tiny little border around my buttons.
Edit: I should mention, in case I didn't make it clear, these are buttons with an image on them, set to flat with the button sized to the image.
Images below:
Number one, I can't for the life of me get these borders to GO AWAY. I've checked everything I can think of. They're:
flat
border 0
no margins
no padding
manually sized to the size of the image (75px)
in a table layout where the columns are all:
manually sized to the width of the image (75px)
borderless
Nothing seems to really "work" to get rid of these. If I size the columns down to be 74px instead of 75px, most of them go away, but a few remain. I've triple and quadruple checked the images, and they don't have anything that I can pick up on that should be causing this... no transparency around the borders, definitely no border that looks like that.
Which leads me to the second problem:
Settings button when dialog is small...
Settings button when dialog is stretched out.
Settings button is also in the same table layout panel.
I've checked all the settings on the table layout panel as well.. I can't find any padding or margin or anything settings that suggest this should be happening.
Does anyone have any experience with this? What am I missing..?

Simple solution: using directly a PictureBox as if it was a button. You can change your image on mouse over or mouse click.

Have you tried a Toolbar/strip/whatever it's called these days? Probably not going to help as I believe it pads on your behalf, but worth a shot.
In the end you can toss the buttons in the trash and write your own control. A single control that manages N buttons will work well here.
I don't understand your second problem. What's the problem? It'll be fixed if you roll your own control anyhow.

While not a fix for the spacing issue, as a workaround you can make that gray gradient currently "behind" the "tabs" and control panel image into a BackgroundImage for the TableLayoutPanel using BackgroundImageLayout of Stretch. While not fixing the spacing issue, it would make it unnoticeable.

Writing a winforms control has its challenges (experience speaking here). I would agree that that is whats needed however. Depending on your project you may consider using XAML and WPF. It provides that fine detail you seem to be looking for in you application.
There are ways to host XAML controls in a winform app, but if you went this route it would be best to create a native WPF application. The reverse is also true (winform controls in a WPF app).

Did you check if the image has transparent pixels around the graphic pixels you want?
May be a simple crop solution.

Related

Why isn't always possible to set a winforms dimensions?

I'm trying to size a checkboxlist control to 500,250 from its current 502,251 (It's an OCD thing) but every time I try, it just reverts to 502,251.
Is it because the parent container is docked in the window? Are there any workarounds?
(This is through the visual designer)
Most likely the control is being resized due to the control's font size. The ListControl does not like to display an item that will be "split" by the bottom edge, so it will resize the height. Try changing the control's font size and adjust again to verify.
No work around, and you really do not what one, because the control is really doing the right thing.
Yes, it is OCD. I have it also, but this one you have to let go. :O) Consider yourself lucky because you are only one or two pixels off. I was five pixels off once, and I had to put a note on my monitor to ignore it. It so bothered me.

How to draw on top of winforms controls with transparency?

I have an app with a bunch of controls in it and I want to place a set of cross hairs on top of it. My first attack used a PictureBox and ran into this problem. The solution that fellow proposes, seems a bit... verbose for what I need.
Is there a simple way draw on top of my form? Note that I don't even need the drawing to be part of a control as it doesn't need to do anything but just be there.
This eventually worked. I had to play some games though because most of the controls I wanted to draw on were not where it expected them to be.
Also, it ran into issues when controls were moved; it failed to redraw and stuff moved with the underlying control. This was fixed by forcing invalidation from the move event for anything that might move.
Does a PictureBox with a transparent image have the same problem as a Panel with BackColor set to Transparent? I'm thinking you could have a PictureBox with the crosshair image in it and move that around, instead of drawing it yourself...

WPF - UserControl sizing on Custom Canvas

I have a custom canvas that I can drop controls on, move, and resize. I need to be able to at least start with a pre-determined size but then allow re-sizing.
My problem is that I have a user control that doesn't appear to resize. I set Height and Width on the user control (works on drop). But then as the control is resized on the canvas the visual size stays the same (the sizing handles are changing). I can see the Height property changing (usercontrol.height) as the control is resized. But again, the appearance of the control stays the same size.
I had a thought that the inner container on the user control should be bound to the usercontrol.height but that didn't seem to help. (or maybe I didn't have the binding right).
On the same canvas, if the dropped control is for example, an Image control, I can set an explicit height on the drop and everything resizes as it should. So it seems to be UserControl thing.
So is there something special I need to do with UserControls to get the visuals to resize? Should I be using explicit height and width to get it all started?
Thanks for any help.
The WPF layout system can be confusing, as you've discovered. There is no substitute for a solid understanding of the layout and measurement system. If you plan on doing much WPF development, it's worth taking 20 minutes to read this article on the layout system and then experimenting for a while in an iterative environment such as Kaxaml until you feel comfortable.
The system is very logical. It won't take long for the penny to drop. Sorry for the indirect answer, but I don't believe there's enough information in your question to really explain what's going on.
You might also look at the HorizontalAlignment and VerticalAlignment properties.
Not a WPF expert but I believe you need to enable auto-sizing in order to achieve the scenario you are looking for. This is done by setting the Height/Width of a control to Double.NaN which essentially says, "I have no specific size". Once you do that, the control should resize to occupy available space based on the need of the control.

Auto-size controls in .NET CF to avoid horizontal scrolling?

I am developing a form in .NET Compact Framework, which hosts a variable number of controls. Every control should have the same width as the form. When there are only a few controls, no vertical scrollbar appears. When there are more controls than they can fit in one form, a vertical scrollbar appears. The width of the controls should then be modified, so that no horizontal scrollbar appears.
What is the best way to achieve this? I am interested in a solution that will work in all platforms/screen sizes and that can support screen orientation changes.
If I get this right, at one point, both a vertical and horizontal scrollbar appear, and you want only the vertical scrollbar? Doesn't setting the Anchor of each control to "Top|Left|Right" solve this problem automatically?
If every control is to be the same width as the form, why not just Dock every control to Top (or Bottom)? It'll take care of the resizing for you then. It might not look very attractive however, so I suggest adding in some empty Panels (docked the same way) to be used as vertical spacers.
I did some quick testing, and it seems, when you add controls, the panel raises the resize event when the added control tiggers the scollbars to go visible. The annoying part is here that the resize event is triggered a couple of times during startup :(
But knowing the compact framework, this might be your best shot at handling this.
Normally on the full framework you could if the DisplayRectangle is bigger than the size of the panel, but no such thing exists on the cf.
Hope this is of some help, I'll see if I can find anything more in the morning.

Is this a good case for use of RoutedCommand?

I have a WPF page that has 2 ContentControls on it. Both of the ContentControls have an image, one being much smaller than the other. When mouse over the larger image I want to show a zoomed in view on the smaller image. Something very similar to this: http://www.trekbikes.com/us/en/bikes/urban/soho/soho/.
I think I want the larger image control to send out something that actually contains an image - which the smaller image control would pick up and display. Would this be a good place to take advantage of RoutedCommands? Can I pass along an image like that?
RoutedCommands seem a bit misplaced in this case... you'll want the mouse to respond smoothly and the last thing you want are commands to be fired off here and there.
You're probably better off using a VisualBrush. While Ian Griffith's example here is a magnifying glass (an early canonical VisualBrush example in WPF) you could easily adapt it to show a portion of your image.

Resources