Click here to Skip to main content
15,893,487 members
Home / Discussions / C#
   

C#

 
QuestionKeyPress Event in DataGrid? Pin
murali_utr4-Aug-04 0:18
murali_utr4-Aug-04 0:18 
AnswerRe: KeyPress Event in DataGrid? Pin
exhaulted4-Aug-04 1:20
exhaulted4-Aug-04 1:20 
Questionhow to add items to contextmenus Pin
Luigi Casana3-Aug-04 23:34
sussLuigi Casana3-Aug-04 23:34 
AnswerRe: how to add items to contextmenus Pin
leppie4-Aug-04 3:50
leppie4-Aug-04 3:50 
GeneralRe: how to add items to contextmenus Pin
Stephan Wright4-Aug-04 23:01
Stephan Wright4-Aug-04 23:01 
GeneralRe: how to add items to contextmenus Pin
angelwhoisadevil5-Aug-04 22:14
sussangelwhoisadevil5-Aug-04 22:14 
GeneralResolution independent forms Pin
biggerR3-Aug-04 23:25
biggerR3-Aug-04 23:25 
GeneralRe: Resolution independent forms Pin
4-Aug-04 3:00
suss4-Aug-04 3:00 
#1, no matter method you use to solve the resizing, you'll probably want to trap your Form's "Resize" event (in the designer, select your form, in the properties window, click the "Events" icon, find Resize, double click it). Trapping the Form's resize will make it easier to resize all the child controls. If you have subcontrols that don't respond well to a parent resize, develop a public method within them that you can call to initiate the same type of resizing once your main form is resized.

#2, I don't know the exact way to get the "true" screen resolution in WinForms (just been using them seriously for about a week now). Screen.PrimaryScreen.WorkingArea (a System.Drawing.Rectangle property) will get you very close -- it returns the largest client area. On my 1280x1024 resolution screen, it returns 1280x994. As a note right here, you probably shouldn't hardcode in "30" or whatever number you find to be the difference between the true resolution and what you see with .WorkingArea. For instance, if I docked my taskbar to the right side of the screen, it would be my X component vs Y component that would shrink. So .WorkingArea may be the best bet anyhow if you truly want to make your UI look standard across all setups.

As far as solutions, there's a couple things you can do:

- Make calculations based on the design time form placement and size vs. the resolution returned by .WorkingArea (basically, come up with fractions/scaling factors/offsets that you can use to dynamically position your objects).

- Do the same as above, but assume a constant, virtual screen size (I've used 5000x5000 before in games). Calculate scales & offsets, probably only need to do this once in your app at the beginning and store the results in sub-properties of the controls if possible, or in some form of List. Then when resize time comes, apply the stored fractional value and multiple/divide it with the virtual screen size : actual screen size (.WorkingArea or other) to come up with the form's true placement.

The second may sound like a lot of work, but sometimes it's nice to initially work with constant units, then just have your program rescale for you when the Resize occurs.

I'm pasting some sample code of the first method I recommended. Note that I use relative offsets in some cases, which is perfectly fine:

lblLoans.Location = new Point(lblLoans.Location.X,(int)((double)Size.Height * 0.5));
lvwShares.Size = new Size(Size.Width - 16, lblLoans.Location.Y - 60);
lvwLoans.Location = new Point(lvwLoans.Location.X,lblLoans.Location.Y + 25);
lvwLoans.Size = new Size(lvwShares.Size.Width,lvwShares.Size.Height);

Size.Width / Size.Height refer to the size of the Form (since this is in my Form's resize method).

Lastly, and I don't have a solution for this, you may want to consider what will happen when the user changes resolution while using your application -- though MANY programs do not properly handle this, you will have accounted for many things a user could do which might cause your UI to break. Ideally, you'd be able to detect the screen resolution change (somehow?) and reset a member variable to reflect the new values, then use these for future calculations. In the Win32 API, there was a message you could trap which would let you know the screen resolution was changed, but I'm not quite sure how to detect that in WinForms....

Good Luck!!
GeneralRe: Resolution independent forms Pin
Heath Stewart4-Aug-04 6:07
protectorHeath Stewart4-Aug-04 6:07 
GeneralRe: Resolution independent forms Pin
Heath Stewart4-Aug-04 6:07
protectorHeath Stewart4-Aug-04 6:07 
Generali want to open new form Pin
shdelpiero3-Aug-04 21:14
shdelpiero3-Aug-04 21:14 
GeneralRe: i want to open new form Pin
sreejith ss nair3-Aug-04 21:41
sreejith ss nair3-Aug-04 21:41 
GeneralRe: i want to open new form Pin
Jay Shankar3-Aug-04 22:08
Jay Shankar3-Aug-04 22:08 
GeneralRe: i want to open new form Pin
exhaulted3-Aug-04 22:36
exhaulted3-Aug-04 22:36 
QuestionReflection: Can base class know about derived class? Pin
PJules3-Aug-04 21:11
PJules3-Aug-04 21:11 
AnswerRe: Reflection: Can base class know about derived class? Pin
Syed Abdul Khader4-Aug-04 0:10
Syed Abdul Khader4-Aug-04 0:10 
AnswerRe: Reflection: Can base class know about derived class? Pin
leppie4-Aug-04 1:16
leppie4-Aug-04 1:16 
GeneralRe: Reflection: Can base class know about derived class? Pin
PJules4-Aug-04 8:51
PJules4-Aug-04 8:51 
GeneralRe: Reflection: Can base class know about derived class? Pin
leppie4-Aug-04 20:45
leppie4-Aug-04 20:45 
GeneralHailing those adept at DirectSound using C# .NET Pin
NietzscheDisciple3-Aug-04 20:45
NietzscheDisciple3-Aug-04 20:45 
GeneralRe: Hailing those adept at DirectSound using C# .NET Pin
4-Aug-04 2:17
suss4-Aug-04 2:17 
GeneralRe: Hailing those adept at DirectSound using C# .NET Pin
NietzscheDisciple4-Aug-04 6:19
NietzscheDisciple4-Aug-04 6:19 
QuestionHow to get image name of a process exactly ? Pin
zuken213-Aug-04 20:26
zuken213-Aug-04 20:26 
Generallocal VCS in .net IDE Pin
samithas3-Aug-04 20:04
samithas3-Aug-04 20:04 
Generalstruct and pointer question in c# Pin
Rulala3-Aug-04 19:54
Rulala3-Aug-04 19:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.