Solved

VB 6 : Detect Screen Resolution & Change Form to  Fit

Posted on 1998-12-15
5
348 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 48
using web browser with BING 40 132
pop out of webbrowser1 control vba6 5 25
VBA: Insert New column with specific format type 12 38
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

829 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