Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

minimize form beyond 112 width? 1

Status
Not open for further replies.

yeller2

Programmer
Feb 8, 2007
69
US
I'm trying to create a form that is < 112 pixels in width. I'm using vs2005 and .net 2.0. As you may know, vs does not let you go below 112 pixels.

I have been able to successfully set the minimum size in my code through the WndProc method and working with the WM_GETMINMAXINFO message. This allows me to resize the form interactively to a size smaller than 112, but I want to resize it programmatically and for some reason, even after setting the minimum, when I try to set the size property, I cannot get below 112.

I've searched for a while now and cannot find a working solution for this situation.

Perhaps someone can think of another control I can use to imitate the form control - it has an x - close button, title area and can contain buttons, and can act like a dialog box (floats).

Thanks

 
Just use a form without a border on it, then add your own heading, border, and buttons.

form1.BorderStyle = FormBorderStyle.None;
 
Thanks a lot, I would that I had had this answer a couple of days ago. Thanks again.
 
This works, but apparently only when in design view - when I run the app. I still cannot get below 112 pixels width.
 
That's strange - now why exactly do you want a window that is so small?

there may be a better solution to what you're doing...
 
I'm just trying to get the look of another a previous version of our app in java, so that there's more seamlessness. I use the window like a floating toolbar, but it is vertical not horizontal.

If you have any ideas feel free to post them, but I think I'm just going to make the items I've placed on the form bigger so that there's not a huge gap.
 
Set the form border style to FixedDialog

Remove any caption/text

If the properties for MaximizeBox and MinimizeBox exist, set these values to False.

now try creating your window. I'm guessing it is a toolbar similar to the size of the one in Photoshop.

See if that works for you.
 
Oh yeah, one more thing...

If that doesn't work, simply put the buttons in a panel sized to the width that you want.

Then set the background color of the form to Pink. Set the panel background to Control (Color) and set the Form Transparency Key to Pink as well.

Only the panel should be floating...
 
I found the solution - I set the formborderstyle to fixedtoolwindow and that did it. Thanks for your help though.
 
Hi,

I had the same problem a few weeks back. JurkMonkey's advice was the only way I found to do this. May I ask(I am a newby), I also wish to create a floating menu (photoshop style), I was going to use a shared array between forms to carry any values set by the floating menu. Is this the way to do this or is there a far better aproach?

Your help will allow me to carry on without worrying if I am approching this in completely the wrong way.

Many thanks.
 
Model View Controller

This is a design pattern that will allow you to work with information between forms. A form, is just a "view" of your data. It should not contain any information that is required for your application to run. You should be able to add a new form (view) and scrap an old view without having to re-write code.

The next thing to look at is the observer pattern. This is the registration of a view to a controller. When a view calls a manipulation on the model(data) through the controller you can notify all other views that are "observers".

Example: we will create a controller and 2 views that will allow you to change tools.

An interface allows you to use a set of methods or properties on a class without actually knowing the class type. As you go through this you should understand further.

public interface IToolbox
{
void ChangeTool(string toolname); //typically you would have an ID or an enumeration
}

Next we create our controller. This class is going to notify all of our views (forms) when a tool is changed. We are using Generics (List<>) they are very handy and VERY easy to use.
public class ToolBoxController
{
private List<IToolbox> toolwindows = new List<IToolbox>();

public void AddObserver(IToolbox toolwindow)
{
toolwindows.Add(toolwindow); //add the observer to the list
}

public void ChangeTool(string toolname)
{
foreach (IToolbox toolwindow in toolwindows)
{
toolwindow.ChangeTool(toolname); //Call the changetool method on each toolwindow that has been added to the list using the AddObserver method...
}
}
}

Now we will create 2 forms that both act as IToolbox's

public class Form1 : IToolbox
{
private ToolBoxController controller = null;

public Form1(ToolBoxController ctrl)
{
InitializeComponent();

controller = ctrl; //give this class a reference to the controller when it is first created.

controller.AddObserver(this); //subscribe this form to the controller so that the ChangeTool method will be called.
}

public void ChangeTool(string toolname)
{
//This method is called by the controller to let us know the tool has been changed. You would typically set the selected tool button on this form to selected.

MessageBox.Show("Form1 is changing tool here");
}

public void toolbutton1_Click(object sender, EventArgs e)
{
controller.ChangeTool("ArrowTool"); //This calls the ChangeTool method on all views when the toolbutton1 button is clicked. This of course will be any tool button that is on your form.
}
}


And now our second form - it will look VERY similar to the first form but would look different. (Hence, a different View)

public class Form2 : IToolbox
{
private ToolBoxController controller = null;

public Form2(ToolBoxController ctrl)
{
InitializeComponent();

controller = ctrl; //give this class a reference to the controller when it is first created.

controller.AddObserver(this); //subscribe this form to the controller so that the ChangeTool method will be called.
}

public void ChangeTool(string toolname)
{
//This method is called by the controller to let us know the tool has been changed. You would typically set the selected tool button on this form to selected.

MessageBox.Show("Form2 is changing tool here");
}

public void toolbutton1_Click(object sender, EventArgs e)
{
controller.ChangeTool("ArrowTool"); //This calls the ChangeTool method on all views when the toolbutton1 button is clicked. This of course will be any tool button that is on your form.
}
}


Now when either form clicks a toolbutton - both forms (views) will update. At this point they will both show MessageBoxes but you would typically set the current selected tool instead.


Are you totally confused yet?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top