views:

700

answers:

3

I am an inexperienced programmer , completely new to programming for windows .

I am writing a little program that I always wanted . Its being written using C# using .net framework. atleast thats what I think I am doing. All the talk about framework and .nets , windows forms , and win32 api has all got me really confused.. :(

anyways I have simple Form object.

 Form f = new Form() ;
 f.Text = "" ;   
 f.ControlBox =false ;

Now How to remove the all the borders on the form except one sides? As in, the side borders should go , but the top border should stay

FormBorderStyle doesn't have anything for this

Also how do you people solve such problems yourself , without asking ? look at others code ? read a a book ? any particular website ? I have googled , but it didn't turn up nothing.

+1  A: 

Gidday,

This is impossible, unfortunately - you can remove the whole border, though, and then draw your own on the form and use OnMouseDown, OnMouseUp and OnMouseMove to do your own dragging...

To solve such a problem myself, I would look at various different ways of verbally representing the problem (eg. "borderless form", "custom borders on winform", etc) and spend a bit of time Googling for it. As my boss wisely says, productivity isn't always about how much code you cut, it's also about what you can learn.

EDIT: As the popular expression goes, "Google knows all" - chances are that, if you spend a bit of time googling and you still can't find anything, then it probably hasn't been solved, or it's very very rare. Another way would be to invest in a few good books, e.g. Windows Forms programming (or even just Windows programming - it's incredibly useful to know about the underlying mechanics of Windows, and things like that are what help turn you into a great developer. A great programmer is good at coding, but a great developer is good at actually building useful software. :)

Fritz H
Thanks a lor for answering.. I googled "custom|draw borders" and that turned up a lot. Ex: http://vicky4147.wordpress.com/2007/03/04/how-to-draw-a-custom-border-around-a-form-or-control/I am pretty sure I should be able to figure this out now
ok that link isn't exactly useful. Since taht border is more like a 'line' , it can't be used for resizing
You'd probably be better off making a borderless form, then adding a Panel to it, making it dock along the top (Dock property of the Panel) and then actually using the OnMouseMove event of the Panel to move the form whenever the left mouse button is held down with the mouse on the panel. Although, I suspect what you're trying to do is make a form that isn't sizable - for that, set `FormBorderStyle` to one if the "Fixed" options (e.g. FixedDialog or FixedToolWindow)
Fritz H
A: 

I don't think it's actually possible to do exactly what you describe, since the .NET Framework is just going to delegate the drawing of your Form's border and title bar to Windows itself, which doesn't have any option for what you describe AFAIK.

Instead, what I would do is use FormBorderStyle.None and then draw any window decorations (title bar, borders) you want manually.

A Google search for "borderless form C#" turns up these sites as the top three hits:

Daniel Pryden
+1  A: 

I assume you've tried FormBorderStyle.FixedSingle? This would display a form with a border at the top only. Anyway, if that isn't the case you can set the forms Region.

Something like...

public static void HideBorders(Form form)
{
    Rectangle newRegion = form.Bounds;
    Rectangle formArea = form.Bounds;
    Rectangle clientArea = form.RectangleToScreen(form.ClientRectangle);

    formArea.Offset(form.Location);
    newRegion.Offset(clientArea.X - formArea.X, 0);
    newRegion.Width = clientArea.Width;
    newRegion.Height = (clientArea.Y - formArea.Y) + clientArea.Height;

    form.Region = new Region(newRegion);
}

As for how do you know what to do? All of the things you mentioned, help files, web forums, books. The main thing is practice, practice, practice. The more you do something the better you should become.

Keith Moore