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.
Related
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();
}
}
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);
The problem is I've already initialized all the initial values for my Properties in my Custom control constructor, for example, PropA = true. But when dragging-n-dropping the final Custom control onto a form, there are some values which are changed to different values (E.g: PropA = false).
I can understand why that happens, that's because of the auto-generated code which do very redundant works. I mean, only properties changed by us (programmers) in the properties window should be added with auto-generated code in the designer.cs files. Why does it have to add redundant code (and sometimes, unwanted code as in my case) to the designer.cs file. Here is the flow of code executing order which makes my default values go away:
public Form(){
//I replace the InitializeComponent() method by its content right in here
myCustomControl = new MyCustomControl(); <---- everything is already
//set up OK at here, no need auto-generated code for my custom properties.
SuspendLayout();
/////Initialize properties
//My custom properties go here, they are already set to default values in my
//custom control constructor (the line right at the very top above).
//And that means, all the auto-generated code below are preparing to erase
//all those default values unexpectedly.
myCustomControl.PropA = false; //While, PropA is already set to true
//in MyCustomControl() constructor and what I want is it should be true, not false
//but the designer doesn't understand me or I have to understand it????
//The same for other custom properties of mine
....
....
ResumeLayout(false);
PerformLayout();
}
I would like to know how to understand the designer or how to make it understand me???
Your help would be highly appreciated!
Thank you in advance!
I would like to hide several textboxes, a label and a button as soon as a button is clicked... however, for some reason, my code doesn't seem to cause this effect. Nothing appears to happen. I'm using WPF.
Here is my code:
private void doSomething_Click(object sender, RoutedEventArgs e)
{
Name.Visibility = Visibility.Hidden;
}
This code doesn't seem to work.. any ideas?
I believe Visibility.Collapsed is what you need and not Visibility.Hidden.
EDIT: Did you try follow up this code with UpdateLayout() method of parent element/component?
Your code seems to work fine, the "Signing in..." label appears after everything else disappear. I suggest you to just copy all your code from the .xaml.cs file and the .xaml file into a new project, but make sure you don't copy the first line"<Window x:Class="..." because it could generate an error if the class name isn't the same in the new project.
For the xaml code I suggest you not think the same as you design windows forms applications. WPF has the layout system, which re-orientates or re-sizes its elements when re-sizing the window. So you should not specify exact numbers in the margin property as if they where coordinates. Create a grid, create rows or columns for each element and then just set the horizontal or vertical alignment or margins. Think different than the old windows forms way.
I've run your code... and it's working great for me. I've not changed anything (except the variable names) so I guess it's a bug from VS.
As said nikolamm94 try to add this.UpdateLayout(); at the end of connect_Click it might help. I tried and it is still working fine. Or maybe create a new VS projet, it already worked for me a few times.
Sorry my answer is not the most helpful, I wanted to put a comment instead but I don't have enough reputation :/
Please refer: https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx
Set to Visible: tb1.Visibility = System.Windows.Visibility.Visible;
Set to Hide: tb1.Visibility = System.Windows.Visibility.Hidden;
You can hide a textbox by going to properties->appearance->visibility, then setting it to "hidden"
I apologise if the title was confusing, it took me nearly 5 minutes to finally think of a title for this one...
Okay, you know how in Visual Studio Express when you add a TabControl to the Form, and you can click on the right-arrow on the top right of the TabControl and it will add a new TabPage, or remove one?
Well, I'm creating a User Control where I need people to be able to switch between Panels (my user control is made up of several Panels). I know this is possible as I've used a Ribbon Control in the past and you could add new buttons etc in the Designer View.
Can somebody please provide any suggestions/advice on how I might go about acheiving this?
Thank you
If I understand your question correctly, you're talking about smart tags.
The process is a little bit involved, so I'm not going to try to post a complete sample. Instead, I'll refer you to this tutorial on the subject. To make a long story short, you have to create a custom designer, and register one or more custom actions. You can use this to create a combo box listing the available panels and switch between them when the selected item is changed.
(Note - the term "smart tags" has two distinct meanings in Visual Studio - I'm specifically talking about the visual designer smart tags, not smart tags in the code editor).
When you make a control that is inherited from Control, you have to make use of a couple of properties such as IsDesignMode, you can then construct event handlers especially for within Design Mode:
if (IsDesignMode){
// Handle the interactivity in Design mode, such as changing a property on the
// Properties toolbox
}
Suppose the control has an event such as MouseClick, you can do this:
private void control_MouseClick(object sender, MouseEventArgs e){
if (IsDesignMode){
// Do something here depending on the Click event within the Designer
}else{
// This is at run-time...
}
}
Another I can think of is 'ShouldSerialize' followed by a publicly accessible property in order to persist the property to the designer-generated code, suppose for example a Control has a boolean property Foo
public bool Foo{
get{ return this._foo; }
set{ if (this._foo != value){
this._foo = value;
}
}
}
public bool ShouldSerializeFoo(){
return true; // The property will be persisted in the designer-generated code
// Check in Form.Designer.cs...
}
If ShouldSerializeFoo returned false, no property is persisted, its the opposite when true, it will be buried within the Form.Designer.cs code...
Hope this helps,
Best regards,
Tom.