zoukankan      html  css  js  c++  java
  • WPF的成长日记

    最近学习wpf编程,学习了让控件跟随窗体的变化而变化。刚开始写还请多见谅!

    主要有两种方式,

    1,label,image,textbox等单独切少的控件可以根据添加viewbox.

    2,如果想要对多控件进行操作,那么就需要先遍历窗体内的控件(注意xaml里面的添加canvas,定位使用canvans.left,canvans.top而不是用margin)cs里面写的代码贴在下面

    窗体打开的时候获取初始的尺寸

    xvalues = this.ActualWidth;
    yvalues = this.ActualHeight;
    SetTag(gd_mode.Children);

    private void SetTag(UIElementCollection uiControls)
    {
    typecon[0] = textBoxMaxSet;
    typecon[1] = textBox1;
    typecon[2] = txt_result;
    typecon[3] = textBox2;
    typecon[4] = button_Set;

    foreach (Control i in typecon)
    {
    con = i;
    con.Tag = con.Width + ":" + con.Height + ":" + Canvas.GetLeft(con) + ":" + Canvas.GetTop(con) + ":" + con.FontSize;
    }
    }

    在窗体Window_SizeChanged里面写上

    if (xvalues != 0)
    {
    double newX = this.ActualWidth / xvalues;
    double newY = this.ActualHeight / yvalues;
    SetControls(newX, newY, gd_mode.Children);
    }

    private void SetControls(double newX, double newY, UIElementCollection uiControls)//改变控件的大小
    {

    foreach (Control i in typecon)
    {

    con = i;
    string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
    double a = Convert.ToSingle(mytag[0]) * newX;
    con.Width = (int)a;

    a = Convert.ToSingle(mytag[1]) * newY;
    con.Height = (int)a;

    a = Convert.ToSingle(mytag[2]) * newX;
    con.SetValue(Canvas.LeftProperty, (double)a);

    a = Convert.ToSingle(mytag[3]) * newY;
    con.SetValue(Canvas.TopProperty, (double)(a));

    double currentSize = Convert.ToSingle(mytag[4]) * newY;
    con.FontSize = currentSize;
    }

    }

  • 相关阅读:
    布隆过滤器
    string.ToString("X")的含义,转换为16进制
    Stream.Write()和Stream.Read(), Stream.Flush的作用,待学习
    linux查看CPU,内存使用情况
    HttpContext.Current.Request.InputStream
    程序员常去的10个顶级开发社区
    JavaScript 对象初探
    PHP – 架構設計 Data Access Layer 篇
    如何用 JavaScript 动态呼叫函数
    PHP – EasyUI DataGrid 资料存的方式
  • 原文地址:https://www.cnblogs.com/xiehaha123/p/11640101.html
Copyright © 2011-2022 走看看