Maximize an UserControl without using a form - c#

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.

Related

Visual Studio Form Designer Showing List of Controls

I know that getting the Form Designer to work is a ticklish business. Generics, x64, subtle problems with the project's XML... But perhaps someone can offer advice about my current problem, which is that a component I created that inherits from TabPage, when I try to view it in the designer shows up as a list of its controls, like this:
Thanks in advance.
You cannot make a TabPage as root of the designer, while you can do the same for a Panel or other container controls. The limitation is because, TabPage can only be hosted in TabControl, not even in the overlay control of the designer:
TabPage cannot be added to a
'System.Windows.Forms.Design.DesignerFrame+OverlayControl'. TabPages
can only be added to TabControls.
A control can be shown as root of the designer when the base class of the control has designer of type of DocumentDesigner. Form and UserControl are such controls which means when you create a new Form1:Form or new UserControl1:UserControl, since the base class derived from a designable control, then the class can be edited in the designer as root.
I believe you can handle your requirement by using UserControl, but for learning purpose (or as a workaround) if you want to make a control deriving from Panel designable, you can copy the following code in a code file:
public class MyControl: MyDesignableControl
{
}
[Designer(typeof(DocumentDesigner), typeof(IRootDesigner))]
public class MyDesignableControl : Panel
{
}
Then save it and then double click on it and you can see you can design it like a root control.
Then after you done with the design, change the Panel to TabPage.
Remarks on
DocumentDesigner
This designer is a root designer, meaning that it provides the
root-level design mode view for the associated document when it is
viewed in design mode.
You can associate a designer with a type using a
DesignerAttribute.
For an overview of customizing design time behavior, see Extending
Design-Time
Support.

Windows form controls error with MetroFramework

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..

c# multiple form with common items from basefrom

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.

Creating a winform user control with no designer

How do I create a WinForms User Control that has no GUI or designer attachment? An example is like the Timer Control, which you drop onto your form and it docks to the bottom but doesn't have any GUI controls?
You need to use System.ComponentModel.Component as base class.
Example :
class Class1 : System.ComponentModel.Component
{
}
Create a class that inherits from System.Windows.Forms.Control. This should change the icon from the normal "class" icon to a "component" icon in the solution explorer. You can see this effect if creating a class and inheriting from say TextBox or Timer

How to access inherited controls in the winforms designer

I'm making some controls which all have to share the same look and some common behavior, although they are meant for different kind of inputs. So I made a BaseClass which inherit from UserControl, and all my controls inherit from BaseClass.
However, if i add controls for BaseClass in the designer, such as a TableLayoutPanel, i can't access them when I'm designing the inherited classes. I see the TableLayoutPanel, but even though he is "protected", i can't modify it or put controls in it through the designer. I've no trouble accesing it by code, but i don't want to lose the ability to use the designer.
Right now, i simply removed all controls from BaseClass, added the layout and all the common controls in each of the inherited class, then use references to manipulate them inside BaseClass. But that doesn't satisfy me at all. Is there a way to make the designer work with inherited protected member controls ?
Environment : C#, .NET 3.5, Visual Studio 2008
EDIT to answer SLaks's suggestion. I tried setting a property, and although I'm not used to use them it doesn't seem to work. Here is the code i tried :
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public TableLayoutPanel TableLayoutPanel1
{
get { return tableLayoutPanel1;}
set { tableLayoutPanel1 = value;}
}
}
public partial class UserControl2 : UserControl1
{
public UserControl2()
{
InitializeComponent();
}
}
When you try to access from the inherited control with the designer to the TableLayoutPanel declared in the base control, you're using a feature in WinForms called "Visual Inheritance".
Unfortunately TableLayoutPanel doesn't support visual inheritance:
http://msdn.microsoft.com/en-us/library/ms171689%28VS.80%29.aspx
That's why the TableLayoutPanel appears blocked in the inherited controls.
Try adding this attribute to the definition of the panel (this may or may not help):
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
You have to design the base controls on their own. Changes are reflected in the designer after you successfully rebuild the controls project. If you make the members public you can edit them but the changes won't persist.
Try making a ParentControlDesigner for your control, overriding InternalControlDesigner, and returning (designerHost.GetDesigner(tableLayoutPanel) as ControlDesigner). designerHost is (IDesignerHost) component.Site.GetService(typeof(IDesignerHost)).
I vaguely remember solving a similar problem by putting the base class it its own DLL and building it first. I've had a rummage but I can't find the project. Sorry.

Categories