开发者

C#: strange rendering in WinForms

开发者 https://www.devze.com 2023-01-30 19:51 出处:网络
For some reason the labels for \"Date From\" and \"Date To\" are rendering strangely on their bottom edges.See how the datepickers are not rendered correctly bec开发者_开发百科ause of this.

C#: strange rendering in WinForms

For some reason the labels for "Date From" and "Date To" are rendering strangely on their bottom edges. See how the datepickers are not rendered correctly bec开发者_开发百科ause of this.

Anyone know why this is occurring? It only occurs when I start the app from the exectuable. It doesn't happen in the IDE.


It looks like the bounds of the Label controls are spilling over into the DateTimePicker controls. Even when a WinForms control has a transparent background, it is not guaranteed to play nice with other controls in the same container. Try reducing the margins/padding on the labels or select both DateTimePicker controls and use the "bring to front" option.


They have a backcolor that matches the form's backcolor.

There are multiple ways to solve this:

  • Right-click on the label and choose "Send to Back"
  • Right-click on the other control and choose "Bring to Front"
  • Make sure the label's AutoSize property is set to true and move it up a little until it doesn't show
  • Make sure the label's Padding property is 0, 0, 0, 0 (zero for each subproperty)


It's frighteningly easy in VS to accidentally change the size and location of controls when manipulating them with the mouse. You may just have to move/re-size them so they don't overlap. Try moving with the arrow keys or explicitly giving them numeric position and size values.


As mickeyf notes, it's very easy to accidentally move or resize a control.

To reduce the likelihood of this happening, VS allows you to lock controls. If you right click anywhere on the form, and select "Lock Controls", this will lock every control on the form. I always found this to be too draconian, and rarely used it.

But what I somehow missed until very recently, each control has a "Locked" property that can be set individually. I find this much more convenient - you just lock the controls that tend to be problematic.

For example, I have several forms that have a toolbar at the top, and another control that exactly fills the rest of the form. It's very easy to accidentally bump this control by a pixel or so, and not realize it. Now I just lock those controls, which is way more convenient than locking everything.

0

精彩评论

暂无评论...
验证码 换一张
取 消