Whenever I drag a metroframework control onto a form window it appears in the bottom left corner of another window instead of on the form itself.
It only happens with metro controls and not regular ones. How to make the controls appear only on the form window?
You need to change the Form to a MetroForm.
Before anything else, you must have a REFERENCE and it should be like this:
using MetroFramework;
or optionally add this:
using MetroFramework.Forms;
For this change this:
public partial class yourForm1 : Form
To this:
public partial class yourForm1 : MetroForm
Among many others there is a nice tutorial here that goes through the whole process:
Downloading
Compiling
Copying the 3 DLLs you need
Creating a new project
Changing the form type (!)
Adding references
Adding the using clause
Adding controls..
Related
I am trying to design some "standalone" tab-pages and later on, I want to add them dynamically to a tab-control in my main form. Visual Studio won't let me open the class extended with TabPage in the designer. Some idea?
using System;
using System.Windows.Forms;
namespace Test.View.Panels {
public class MainStatusTabPage : TabPage {
public MainStatusTabPage() {
}
}
}
When I right-click the class in the Solution Explorer and selecting "View Designer", I get the following message (the Designer doesn't show up):
To add components to your class, drag them from the Toolbox and use
the Properties window to set their properties. To create methods and
events for your class, switch to code view.
When I right-click the class in the Solution Explorer and selecting "View Designer", I get the following message (the Designer doesn't show up):
To add components to your class, drag them from the Toolbox and use the Properties window to set their properties. To create methods and events for your class, switch to code view.
This is normal behavior as a TabPage is just a container that holds other controls, nothing more. As #PanagiotisKanavos mentioned above:
A Tab Page is a container, not the actual content of the tab. In all examples that use complex content you'll see that the content is a custom component, eg a User control, that's added into the tab
With this in mind, you can just create a UserControl with all the other controls you would need and then add this new instance (UserControl) to the TabPage itself.
My project built a panel with a pictureBox. This panel should be possible to maximize (for pictures displaying). I want to do that by creating a class like that:
public partial class ImageDisplay : UserControl
and in designer I add a picturebox and later do something with that.
It's not working properly, coz I cannot maximize ImageDisplay class (while it inherits by UserControl). I tried to do that just by changing it on:
public partial class ImageDisplay : Form
and then change the form's properties.
But I can't do that in that way, coz after I built my project, I use created .dll file in another program. And this program is working properly, when I use the class inheriting from UserControl. But when it inherits from the form, this program crushs.
I don't know why that is working in that way, I just get this code yesterday, when I've never coded in C# before.
So every hint or help or maybe good link would be helpful.
it's any way to inherit form from baseForm, f.e:
i have Baseform with menu and some button. Now I want to use it in my second form, but i would not copy-paste, but only:
public partial class Form1 : BaseForm
and now i have some problems, because compilator send me bugs:
Message 1 The designer could not be shown for this file because none
of the classes within it can be designed. The designer inspected the
following classes in the file:
dziedziczony --- The base class '_10widokow.BaseForm' could not be
loaded. Ensure the assembly has been referenced and that all projects
have been built.
Those errors probably due to your BaseForm either not being referenced, or you have other problems outside of the scope of the question.
Controls on a form are added by the InitialiazeComponents method generated by the Form graphical editor. You don't need to inherit to bring in a basic set of controls, but simply copy the generated code out to a common location.
Then call in the constructor of the forms in which you want the base controls.
I would like to know how I could possibly modulate my views in an application. Let me explain.
Instead of building my view and adding all the components in one screen. I want to say put each panel in its own class / form and then have a main form where I can add and remove these 'modular' panels.
Is this possible and how would I go about doing it?
In Windows Forms there is the concept of an empty component called UserControl, that can be freely designed and added at any time to another component or form container. UserControls are used very often in order to create flexible and exchangable UI. You can create a UserControl item in Visual Studio like this:
Name the new control:
After that you can design your UI control:
When your are done with the design, compile your project/solution and go to the form where you want to add your newly designed control. In the toolbar panel you will see your new UserControl, which can be added to the form with drag & drop (with the mouse):
You can create as many UserControls as you want and add/remove them to/from your form.
All of this steps can be done completely in the code. In order to create new view of this kind, you need to create a new class that inherits the predefined UserControl class:
public class EditorUserControl : UserControl
{
}
Every Control element has a ControlsCollection that holds/contains components of type Control that are drawn when the UI is shown. In order to add your new control to the main panel you need to add it to the controls collection:
public partial class EditorUserControl : UserControl
{
public EditorUserControl()
{
var button = new Button();
button.Text = "Import";
this.Controls.Add(button);
}
}
Note, that when adding components manually, you are responsible for sizing and position them. Predefined layout panels can help you here:
TableLayoutPanel - layout with cells
SplitPanel - horizontal or vertical predefined resizable panels
etc.
Now all that left is to add the new user control to the main form just like you added the UI elements to your own control:
var simpleEditor = new EditorUserControl();
simpleEditor.Dock = DockStyle.Fill;
this.Controls.Add(simpleEditor);
You can adjust the UI control settings through its predefined properties.
You can mix predefined containers and UserControls in order to achieve the desired UI:
There are a lot of good beginners tutorials for C# and VS and .NET:
Channel9 tutorials
MSDN Visual Studio UI tutorials
Composite UserControl tutorial
Developing with Windows Forms Documentation and Examples
This is definitely possible. I will use WinForms but there are similar ways in WPF such as frames.
In WinForms you can create a new User Control for each 'modular' panel which will automatically create .cs and .designer.cs files just like in a normal Form. You can then add logic and functionality to the panels as if they were forms themselves. All that would then remain is to add the logic to the form to load the default panel on startup and think of ways of how other panels can be brought into view (e.g. a next button or having a panel on each tab in a tab control). Showing a panel in a form (or any other user control for that matter) is achieved by creating an instance of your desired panel and adding it to you form/control's Controls property like so:
public Form1()
{
InitializeComponent();
MyPanel panel = new MyPanel();
this.Controls.Add(panel);
}
I need to make a UserControl that can be used for multiple projects. But it needs to be a Form so the user can just add a reference to the library and call the form.
I've seen third party companies like Telerik and DevExpress use custom forms that can be added to a project.
How would I accomplish this? I've been looking through SO and various posts from Google, but have not been successful in my searches.
EDIT I was assuming it had to be a UserControl for some reason. But it doesn't. I took the suggestion of just adding a form and calling it from that namespace. Works exactly as needed. Thanks everyone.
Just create the form in your library, make it public, and you can call it from anywhere.
Methods to create and call form are:
YourFormClassName FormForUser = new YourFormClassName();
FormForUser.Show();
FormForUser.ShowDialog();
Maybe I don't understand. If I do, then it's straight forward.
Add a project (ProjectWithReusedForm) to your solution that contains the form to be reused.
Add a reference to ProjectWithReusedForm in the second project where you want to use the form
Add a 'using ProjectWithReusedFormNamespace' to the code where you want to use the form
You then can add the statement ReusedForm myForm = new ReusedForm();
You can create BaseForm (either add it into a project directly by adding .cs file or reference something compiled - class library to example). Then just add a new form to a project
namespace MySolution
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
and chang Form to BaseForm
public partial class Form1 : BaseForm
Just Create form with all controls. and create empty user control
Ex:
do this code inside usercontrol constructor after initialize function
dim obja as new RegForm()
obja.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
obja.Visible = true
obja.Dock = System.Windows.Forms.DockStyle.Full
me.Controls.Add(obja)
You have to be careful here. Your tag lists winforms, so I am assuming you are using .net and UserControls. Winforms only allows a single form per page. You can add multiple UserControls to a page. If you go with the base form route, the programmer will have to add everything else to your base page. UserControls will offer a little more flexibility in that they can be added to an existing page.