需要帮助以任何屏幕分辨率运行Windows应用程序 [英] Need help in running windows application at any screen resolution

查看:75
本文介绍了需要帮助以任何屏幕分辨率运行Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在开发一个Windows应用程序,我想让它在任何屏幕分辨率下运行。请你告诉我该怎么做..



谢谢

解决方案

没有魔法代码可以使它工作。如果你想要一个优雅地重新调整大小的用户界面,那么使用winforms是一个错误 - 你需要看一下WPF,这是为了做那种事情。



在Winforms中没有自动方式来扩展内容 - 你可以使用Anchor和Dock属性来扩展和收缩控件,但这根本不会改变字体大小,所以你可以找到哪些巨大的按钮,带有微小的中间的文字。您必须处理resize事件,并手动更改它们。


访问链接...



http://social.msdn.microsoft.com/Forums/en -US / winformsdesigner / thread / 6753e124-70c1-4e3a-b8f7-f4c076837627 [ ^ ]



快乐编码!

:)


这是一个代码块,只做你想要的。



注意:

它不是我自己的代码,虽然我在10年前写了类似的东西。

此样本来自 Planet源代码



每当我试图粘贴链接时,它就会因为某些疯狂的原因而出现问题。

所以我只需粘贴下面的代码。



选项 明确 开启
公共 Form1

Dim c( 6 0 作为 字符串
Dim xx,yy 作为


私有 Sub Form1_Load( ByVal sender As 系统。对象 ByVal e 作为 System.EventArgs)句柄 MyBase .Load
xx = .ClientSize.Width
yy = .ClientSize.Height
taga( Me ,xx,yy)
' Me.WindowState = FormWindowState.Maximized'可选

结束 Sub

私有 Sub Form1_Resize( ByVal 发​​件人作为 对象 ByVal e As System.EventArgs)句柄 MyBase .Resize
Dim sX,sY As Double
Dim j As 整数

错误 恢复 下一步
sX = .ClientSize.Width / xx
sY = Me .ClientSize.Height / yy
对于 j = 1 c.GetUpperBound( 1
mudar(,c( 0 ,j),j,sX,sY)
下一步 j
结束 Sub
私有 Sub taga( ByVal ct 作为 对象 ByVal w 作为 ByVal h 作为
Dim i, k 作为 整数
Dim ctl 作为控制
对于 每个 ctl ct.Controls
如果 ctl.Name = 然后 退出 对于
k = c.GetUpperBound( 1
ReDim 保留c( 6 ,k + 1
c( 0 ,k + 1 )= ctl.Name
c( 1 ,k + 1 )= ctl.Left
c( 2 ,k + 1 )= ctl.Top
c( 3 ,k + 1 )= ctl.Width
c( 4 ,k + 1 )= ctl.Height
c( 5 ,k + 1 )= ctl.Font.Size
c( 6 ,k + 1 )= ctl.Font.Style
i = ctl.Controls.Count
如果 i> 0 然后
taga(ctl,ctl.Width,ctl.Height)
结束 如果
下一步 ctl
结束 Sub
私有 Sub mudar( ByVal cm As 对象 ByVal s 作为 字符串 ByVal n 作为 整数 ByVal x 作为 Double ByVal y As Double
Dim ct 作为控制
对于 每个 ct cm.controls
如果 ct.Name = s 然后
ct.Left = c( 1 ,n)* x
ct.Top = c( 2 ,n)* y
ct.Width = c( 3 ,n)* x
ct.Height = c( 4 ,n)* y
如果 x< y 然后
ct.Font = System.Drawing.Font(ct.Font.Name ,c( 5 ,n)* x)
否则
ct.Font = System.Drawing.Font(ct.Font.Name,c( 5 ,n)* y )
结束 如果
ct.Font = System.Drawing.Font(ct.Font,c( 6 ,n))
退出 对于
其他
mudar(ct, s,n,x,y)
结束 如果
下一步
结束 Sub

结束


Hi all

I m developing one windows application and i want it to run in any screen resolution.can u please tell me how to do that..

Thank you

解决方案

There is no "magic code" which makes it work. If you want to have a UI that re-sizes gracefully, then using winforms is a mistake - you need to look at WPF which is designed to do that kind of thing.

There is no automatic way to stretch things in Winforms - you can make the controls expand and contract by using the Anchor and Dock properties, but that does not change font sizes at all, so you can end up which huge buttons, with tiny text in the middle. You would have to handle the resize event, and change them all manually.


visit link...

http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/6753e124-70c1-4e3a-b8f7-f4c076837627[^]

Happy Coding!
:)


Here is a code block to do JUST what you want.

NOTE:
Its not my own code, although i did write something similar over 10 years ago.
This sample is from Planet Source Code

Every time i tried to paste the link it conked out for some mad reason.
So i have simply pasted the code below.

Option Explicit On
Public Class Form1

    Dim c(6, 0) As String
    Dim xx, yy As Long


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xx = Me.ClientSize.Width
        yy = Me.ClientSize.Height
        taga(Me, xx, yy)
        'Me.WindowState = FormWindowState.Maximized 'Optional

    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Dim sX, sY As Double
        Dim j As Integer

        On Error Resume Next
        sX = Me.ClientSize.Width / xx
        sY = Me.ClientSize.Height / yy
        For j = 1 To c.GetUpperBound(1)
            mudar(Me, c(0, j), j, sX, sY)
        Next j
    End Sub
    Private Sub taga(ByVal ct As Object, ByVal w As Long, ByVal h As Long)
        Dim i, k As Integer
        Dim ctl As Control
        For Each ctl In ct.Controls
            If ctl.Name = "" Then Exit For
            k = c.GetUpperBound(1)
            ReDim Preserve c(6, k + 1)
            c(0, k + 1) = ctl.Name
            c(1, k + 1) = ctl.Left
            c(2, k + 1) = ctl.Top
            c(3, k + 1) = ctl.Width
            c(4, k + 1) = ctl.Height
            c(5, k + 1) = ctl.Font.Size
            c(6, k + 1) = ctl.Font.Style
            i = ctl.Controls.Count
            If i > 0 Then
                taga(ctl, ctl.Width, ctl.Height)
            End If
        Next ctl
    End Sub
    Private Sub mudar(ByVal cm As Object, ByVal s As String, ByVal n As Integer, ByVal x As Double, ByVal y As Double)
        Dim ct As Control
        For Each ct In cm.controls
            If ct.Name = s Then
                ct.Left = c(1, n) * x
                ct.Top = c(2, n) * y
                ct.Width = c(3, n) * x
                ct.Height = c(4, n) * y
                If x < y Then
                    ct.Font = New System.Drawing.Font(ct.Font.Name, c(5, n) * x)
                Else
                    ct.Font = New System.Drawing.Font(ct.Font.Name, c(5, n) * y)
                End If
                ct.Font = New System.Drawing.Font(ct.Font, c(6, n))
                Exit For
            Else
                mudar(ct, s, n, x, y)
            End If
        Next
    End Sub

End Class


这篇关于需要帮助以任何屏幕分辨率运行Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆