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;
    }

    }

  • 相关阅读:
    javaee后台适合用的编辑器插件
    昨天做了一个使用javamail发送文件的demo
    jsp页面可以巧用模态框
    jQuery 表单验证插件——Validation(基础)
    jsp引入struts标签,引入自己写的jquery需要注意的问题
    LeetCode的神坑
    Java函数结束时的内存回收坑
    递归与回溯1
    由树的定义和递归想到的
    复杂一点的二叉树递归
  • 原文地址:https://www.cnblogs.com/xiehaha123/p/11640101.html
Copyright © 2011-2022 走看看