IconPadding property on an ErrorProvider doesn't work - c#

So I am trying to make a space between an icon used for validation of a form and a textbox. Right now, I in Properties Window, I am setting ErrorProvider's IconPadding property (under ContainerControl section) to something like 5 but it doesn't make a difference. If matters, the icon I use is 48x48, so it doesn't have a preferred size, but I will change that later (to 16x16).

try this:
this.errorProvider.SetIconPadding(this.textBox, 5);

Related

TabControl ItemSize with TabPage ImageKey

I have a TabControl where I want to keep the tabs to a fixed size and I want icons in the tabs. I have set TabControl.SizeMode = Fixed and TabControl.ItemSize = 100, 18. I have also set TabControl.ImageList and am assigning images to the tabs via TabPage.ImageKey.
Here is what it looks like if I comment-out assigning the ImageKey:
And here is what it looks like if I am assigning the ImageKey:
Is there some sort of "alignment" for the icons? I want them to be on the far left in the blank space, but instead they are starting where the text starts. Any suggestions?
(BTW - if I set TabControl.SizeMode = Normal, I get the tab content the way I want it, but the tabs aren't a fixed size):
I can verify the issue that you are seeing with TabControl.SizeMode = Fixed (on Windows 10). I initially seen it in the designer when configuring a TabPage with an icon. However the irritating thing is that the issue corrected itself if the designer is closed and reopened. This suggests a window style setting of some sort and there are some Tab Control Styles set in the CreateParams Property based on the SizeMode Property. However, I found no solution in attempting to apply the TCS_FORCEICONLEFT style. If the ImageIndex property is set prior to the control being shown, then the alignment is as desired. So I figured that there must be something being configured on handle creation.
If you call the form's RecreateHandle method after setting the TabPage.ImageIndex property, the form redraws and all looks good. However this cause the form to blink. Calling the Control.RecreateHandle method on the TabControl also works. This is a protected method and would necessitate using a derived TabControl to expose the method or you could use Reflection to invoke the method.
public class MyTC : TabControl
{
public void FixIcon()
{
RecreateHandle();
}
}

Creating popup without possibility to tab to a background element

I am trying to create a popup but when it is open it is still possible to use the tab key to switch the focus to an element in the background (e.g. to a button and use space to press is). The only way I found until now is to check on every lostFocus event (which also fires for every element contained in the Border element) and check if the focus is now in a element inside the Border. If not I manually set the focus.
Is there a nicer way to keep the focus within the Border (or a Grid,...)
I'm working on a Windows 8 App.
Do you mean that using a Modal Dialog with Form.ShowDialog(Owner) still allows you to focus the parent components with Tab?
Can you give a sample of your code call?
Form2 form = new Form2(); //Make an instantiation of your Form
form.ShowDialog(); //ShowDialog()!!! NOT form.Show()!!! Or anything else :/
A few ideas:
Set Enabled to False on the background visual tree, though that might change the way things look if you still want to show them partly
Set IsHitTestVisible to False to disable pointer input
Use RenderTargetBitmap.Render() if targeting Windows 8.1 to render the content of the background to an image and simply replace all that visual tree with an image of it

Visual Studio wont let me remove the maximise/minimise button/icon etc

I have Form1.cs which I have set in properties to be borderless, without an icon, max/min buttons (and the changes are shown visually in Form1.cs), but when I debug/run, all of those controls stay the same as they previously were. The properties are then found in my code under private void InitializeComponent() as this.ShowIcon = false; etc.. Form1.Designer.cs is always empty though, have I messed up some settings somehow that overrides my form1.cs selections?
Have you tried setting the forms .MaximizeBox and .MinimizeBox to false ?
If so, can you please post the contents of that InitializeComponent method.
Winforms have properties like MinimizeBox, MaximizeBox and ShowIcon on the designer if you set then to False. Then you wont require any line of code in private void InitializeComponent()
Design view only show what is set in Form1.Design.cs, and not your custom code (except for some events and properties like resize...) Did you overwrite any design values in your code after you run InitializeComponents?
The easiest way is to cross-reference Form1.
If you're trying to remove the entire title bar you'll want to set the FormBorderStyle to None. If that doesn't work try and set a breakpoint after your form has loaded and check the values to make sure they are what you think they should be. This should not require any coding.

link on the form title

How can I add a clickable website link inside a window's form title?
To make an area within the title bar clickable, you must override WndProc and handle WM_NCLBUTTONDOWN
In order to make it look like a link, you'll need to also handle WM_NCPAINT and WM_NCMOUSEMOVE.
You can rewrite the form code and draw the title yourself (you set FormBorderStyle property to none, create a TextBox, etc). There's no build-in mechanism for this in .NET framework.
You can't.
Technically, you can, if you draw the window chrome yourself, but you reallly shouldn't.

Limit resizable dimensions of a custom control (c# .net)

I am making a user control in MS Visual C#, and there is one thing that I just can't find an answer to:
How do I limit which dimensions a control can be resized in during design view?
For a clear example of what I'm asking, the built in TrackBar control can only only be made wider, not taller, and only displays the resizing squares on the left and right in design mode. Is there a way to replicate this for a user control?
I have tried setting MinimumSize and MaximumSize values in the designer for my control, but this doesn't give ideal results.
To get the full behavior you're talking about (no adorners on top/bottom or left/right) and custom functionality inside the design time environment, you'll probably have to resort to building a custom control designer for your control.
This is a huge topic, as there are a lot of things you can do. Effectively what you'd do is create a class that inherits from ControlDesigner, override whatever functionality you need, then register it on your user control with the DesignerAttribute, specifying typeof(IDesigner) for the 2nd parameter (and your custom ControlDesigner-derived type for the first).
Enhancing Design-time Support
Custom Designers
ControlDesigner class example
Custom Design-time Control Features in Visual Studio .NET
Now, in the case of TrackBar, it has its own designer that overrides the ControlDesigner.SelectionRules property. This property simply lets you return an enumeration value (it's a Flags enum, so you can OR them together) indicating how your design-time selection adorners appear (or not appear). Once you've restricted design-time resizing via a designer, it's simply up to your control itself to constrain its own size vai SetBoundsCore.
I'm fairly sure you can do this with Control.SetBoundsCore, as described here.link text
I am not sure for the resizing square but MaximunSize and MinimumSize are the right values for you.
But it's not enough to set them in the constructor of your class because everytime you drop an instance of your control from the designer to a form these values get set after the constructor.
You should:
override MinumumSize and MaximumSize, and do net set the base value from your value but your value.
private Size maxSize = new Size(100, 5);
public override Size MaximumSize
{
get { return base.MaximumSize; }
set { base.MaximumSize = maxSize; }
}
create a public method in your class:
public bool ShouldSerializeMaximumSize()
{
return false;
}
and
private void ResetMaximumSize()
{
me.MaximumSize = maxSize;
}
These methods are a convention from the Windows Forms Desinger: http://msdn.microsoft.com/en-us/library/53b8022e.aspx

Categories