Solved

VB 6 : Detect Screen Resolution & Change Form to  Fit

Posted on 1998-12-15
5
339 Views
Last Modified: 2008-01-09
What is the code for changing the form size when the resolution is changed on a windows 95 environment?
0
Comment
Question by:mirna
  • 2
  • 2
5 Comments
 

Author Comment

by:mirna
ID: 1450290
Edited text of question
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1450291
.ScreenX and .ScreenY will give you current dimensions. But if you auto re-size when the user grows their desktop are you not defeating the purpose of the user going to a higher rez? After all if I'm moving up in rez, I want *MORE* desktop - don't make your app grow to take the same amount of screen real estate!

Size everything to fit on 640x400 or 800x600 and leave it at that.

M

0
 

Author Comment

by:mirna
ID: 1450292
I don't need the user to view the form. I just had to create it in a 1280x1024 rez so that I could fit all the contents of a paper form on it. I found a way to make it stay the same size but now when I print it, it prints the form small. I tried capturing it to a pictue box, but printing it as a picture makes the font look distorted. I would really appreciate any advice you could give me.
0
 
LVL 2

Accepted Solution

by:
cedricd earned 100 total points
ID: 1450293
i founded an ocx to do that if you want it send me a mail at cedric.defosse@moodif.com or see on this site http://www.geocities.com or at http://vbwire.com/nl?www.toolcity.net/~djcomlab/

here is an example of a code using it (it's called displayer1)

Private Sub Cmdchng_Click()
Dim Doit As Integer


Doit = 0 '''this is used so no unecessary changes are made''

If Displayer1.NewXRes <> CurrentResX Or Displayer1.NewYRes <> CurrentResY Then
  Displayer1.SetNewRes
  Doit = Doit + 1
End If
If Displayer1.NewFontMode <> CurrentFontMode Then
  Displayer1.SetNewFontMode
  Doit = Doit + 1
End If
If Displayer1.NewColorPal <> CurrentColorPal Then
  Displayer1.SetNewColorPal
  Doit = Doit + 1
End If
If Doit <> 0 Then
 
 Displayer1.RememberMeOk (ProgLoc)
 Displayer1.Reboot
Else
  Msg = "No Changes to be made!"
  MsgBox Msg
End If
End Sub

Private Sub CmdChng2_Click()
Dim Doit As Integer

Displayer1.BackupAllSettings
Doit = 0 '''this is used so no unecessary changes are made''

If Displayer1.NewXRes <> CurrentResX Or Displayer1.NewYRes <> CurrentResY Then
  Displayer1.SetNewRes
  Doit = Doit + 1
End If
If Displayer1.NewFontMode <> CurrentFontMode Then
  Displayer1.SetNewFontMode
  Doit = Doit + 1
End If
If Displayer1.NewColorPal <> CurrentColorPal Then
  Displayer1.SetNewColorPal
  Doit = Doit + 1
End If
If Doit <> 0 Then
 Displayer1.RememberMeOk (ProgLoc)
 Displayer1.Reboot
Else
  Displayer1.KillBackup
  Msg = "No Changes to be made!"
  MsgBox Msg
End If
End Sub

Private Sub CmdResFly_Click()
Displayer1.SetNewResNOW
If WindowState = 0 Then
 Move (Screen.Width - ChangeFrm.Width) / 2, (Screen.Height - ChangeFrm.Height) / 2
End If
End Sub





Private Sub CmdRestore_Click()
Displayer1.RestoreSettings
Displayer1.KillBackup
Displayer1.RememberMeOk (ProgLoc)
Displayer1.Reboot

End Sub

Private Sub Form_Load()
ProgLoc = App.Path & "\" & App.EXEName & ".exe"

''''Set these to so you can check new versus old'''
CurrentColorPal = Displayer1.FindCurrentPal
CurrentFontMode = Displayer1.FindCurrentFontMode
CurrentResX = Val(Left$(Displayer1.FindCurrentRes, 3))
CurrentResY = Val(Right$(Displayer1.FindCurrentRes, 3))
'''''''''''''''''''''''''''''

'''Set Current Text Boxes''''''
txtRes.Text = Displayer1.FindCurrentRes
txtColor.Text = Displayer1.FindCurrentPal & "-bit"
txtFont.Text = Displayer1.FindCurrentFontMode
''''''''''''''''''''''''''''''''

'''my usual defaults''''
Displayer1.NewXRes = 800
Displayer1.NewYRes = 600
Displayer1.NewColorPal = 16
Displayer1.NewFontMode = "SMALL"
'''''''''''''''''''''''''

''''Set option values'''''
optRes2.Value = True
optPal2.Value = True
optFont1.Value = True
'''''''''''''''''''''''''

'''Set Switch-to Text boxes''''''
txtNewRes.Text = Displayer1.NewXRes & " x " & Displayer1.NewYRes
txtNewColor.Text = Displayer1.NewColorPal & "-bit"
txtNewFont.Text = Displayer1.NewFontMode
'''''''''''''''''''''''''''''
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label15.Caption = "X"

End Sub

Private Sub Form_Resize()
If WindowState = 0 Then
 Move (Screen.Width - ChangeFrm.Width) / 2, (Screen.Height - ChangeFrm.Height) / 2
End If

End Sub

Private Sub Label15_Click()
Dim Ans As Integer
Ans = MsgBox("Are you sure you want to Quit?", 1, "Quitting?")
If Ans <> 2 Then End

End Sub

Private Sub Label15_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label15.Caption = "Exit?"


End Sub

Private Sub optFont1_Click()
Displayer1.NewFontMode = "SMALL"
txtNewFont.Text = Displayer1.NewFontMode

End Sub

Private Sub optFont2_Click()
Displayer1.NewFontMode = "LARGE"
txtNewFont.Text = Displayer1.NewFontMode
End Sub

Private Sub optPal1_Click()
Displayer1.NewColorPal = 8
txtNewColor.Text = Displayer1.NewColorPal & "-bit"
End Sub

Private Sub optPal2_Click()
Displayer1.NewColorPal = 16
txtNewColor.Text = Displayer1.NewColorPal & "-bit"
End Sub

Private Sub optPal3_Click()
Displayer1.NewColorPal = 24
txtNewColor.Text = Displayer1.NewColorPal & "-bit"

End Sub

Private Sub optRes1_Click()
Displayer1.NewXRes = 640
Displayer1.NewYRes = 480
txtNewRes.Text = Displayer1.NewXRes & " x " & Displayer1.NewYRes
End Sub

Private Sub optRes2_Click()
Displayer1.NewXRes = 800
Displayer1.NewYRes = 600
txtNewRes.Text = Displayer1.NewXRes & " x " & Displayer1.NewYRes
End Sub

Private Sub optRes3_Click()
Displayer1.NewXRes = 1024
Displayer1.NewYRes = 768
txtNewRes.Text = Displayer1.NewXRes & " x " & Displayer1.NewYRes
End Sub

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1450294
Printing is not dependent on screen res. I don't understand what the problem is.

Don't use "Printer.PrintPicture" to render the form to paper.

Capture your data in fields (on several screens if necessary), *THEN* draw your form from scratch on the printer device. This will give you nice, crisp text and graphics and will keep you screen size independent.

I think from what you said that you have a large form and are printing the form as a single graphical entity. This is the *WRONG APPROACH* to this problem.

You can generalize a print routine to print both to a screen object and to the printer. You pass your routine an OBJECT that is set (prior to the call) to either the screen object or the PRINTER object. This way you can have *one* routine for both onscreen preview and for printing.

You'll have to essentially completely rip out what you've done so far tho. Code your routine like this:

PRIVATE SUB Render ( Tgt AS OBJECT )
If TypeName( Tgt ) <> "Printer" Then Tgt.Cls
Tgt.ScaleWidth = ...
Tgt.Line ...
Tgt.Print ...
Tgt.CurrentX = ...
If TypeName( Tgt ) = "Printer" Then Tgt.EndDoc
END SUB

You'll need the occassional conditional test for the kid of object as some codes are specific to the printer and others specific to screen objects.



0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now