Exemple #1
0
        private void form1_Load(object sender, EventArgs e)
        {
            if (File.Exists(jsonFile))
            {
                loadedConfig = JsonConvert.DeserializeObject <Mask.Config>(File.ReadAllText(jsonFile));
            }

            if (loadedConfig == null || loadedConfig.Equals(new Mask.Config()))
            {
                loadedConfig                    = new Mask.Config();
                loadedConfig.ProcessList        = protectedProcessList;
                loadedConfig.Column             = 3;
                loadedConfig.Row                = 3;
                loadedConfig.Alpha              = 50;
                loadedConfig.FontSize           = 14;
                loadedConfig.Angle              = 30;
                loadedConfig.OutlineWeight      = .5f;
                loadedConfig.IsShowComputerName = false;
                loadedConfig.IsShowIPAddr       = true;
                loadedConfig.IsShowMacAddr      = true;
                loadedConfig.IsShowLoginUser    = false;
                loadedConfig.IsShowQrCode       = true;
                loadedConfig.QrCodeAlpha        = 50;
                loadedConfig.QrCodePos          = 0;
                loadedConfig.QrCodeSize         = 100;
                File.WriteAllText(jsonFile, JsonConvert.SerializeObject(loadedConfig));
            }
            foreach (var process in loadedConfig.ProcessList)
            {
                processList.Items.Add(process);
            }
            column.Text             = loadedConfig.Column.ToString();
            row.Text                = loadedConfig.Row.ToString();
            alpha.Text              = loadedConfig.Alpha.ToString();
            fontSize.Text           = loadedConfig.FontSize.ToString();
            angle.Text              = loadedConfig.Angle.ToString();
            outlineWeight.Text      = loadedConfig.OutlineWeight.ToString();
            showCpuName.Checked     = loadedConfig.IsShowComputerName;
            showIpAddr.Checked      = loadedConfig.IsShowIPAddr;
            showLoginUser.Checked   = loadedConfig.IsShowLoginUser;
            showMacAddr.Checked     = loadedConfig.IsShowMacAddr;
            showQrCode.Checked      = loadedConfig.IsShowQrCode;
            qrCodeAlpha.Text        = loadedConfig.QrCodeAlpha.ToString();
            qrCodePos.SelectedIndex = loadedConfig.QrCodePos;
            deltaTime.Text          = loadedConfig.ChangePosDeltaTime.ToString();
            qrCodeSize.Text         = loadedConfig.QrCodeSize.ToString();
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            bool containError = false;

            Mask.Config newConfig = new Mask.Config();
            if (int.TryParse(column.Text, out int _column))
            {
                newConfig.Column = _column;
            }
            else
            {
                containError     = true;
                column.BackColor = Color.IndianRed;
            }
            if (int.TryParse(row.Text, out int _row))
            {
                newConfig.Row = _row;
            }
            else
            {
                containError  = true;
                row.BackColor = Color.IndianRed;
            }
            if (int.TryParse(fontSize.Text, out int _fontSize))
            {
                newConfig.FontSize = _fontSize;
            }
            else
            {
                containError       = true;
                fontSize.BackColor = Color.IndianRed;
            }
            if (int.TryParse(angle.Text, out int _angle))
            {
                newConfig.Angle = _angle;
            }
            else
            {
                containError    = true;
                angle.BackColor = Color.IndianRed;
            }
            if (int.TryParse(alpha.Text, out int _alpha))
            {
                newConfig.Alpha = _alpha;
            }
            else
            {
                containError    = true;
                alpha.BackColor = Color.IndianRed;
            }
            if (float.TryParse(outlineWeight.Text, out float _outlineWeight))
            {
                newConfig.OutlineWeight = _outlineWeight;
            }
            else
            {
                containError            = true;
                outlineWeight.BackColor = Color.IndianRed;
            }
            if (processList.Items.Count == 0)
            {
                containError          = true;
                processList.BackColor = Color.IndianRed;
            }
            else
            {
                newConfig.ProcessList = new List <string>();
                foreach (string process in processList.Items)
                {
                    if (string.IsNullOrEmpty(process))
                    {
                        containError          = true;
                        processList.BackColor = Color.IndianRed;
                        break;
                    }
                    newConfig.ProcessList.Add(process);
                }
            }

            if (!(showCpuName.Checked || showIpAddr.Checked || showMacAddr.Checked || showLoginUser.Checked))
            {
                containError = true;
                MessageBox.Show("显示的文字至少需要勾选一个!");
                return;
            }
            else
            {
                newConfig.IsShowQrCode       = showQrCode.Checked;
                newConfig.IsShowComputerName = showCpuName.Checked;
                newConfig.IsShowIPAddr       = showIpAddr.Checked;
                newConfig.IsShowLoginUser    = showLoginUser.Checked;
                newConfig.IsShowMacAddr      = showMacAddr.Checked;
            }
            newConfig.IsShowQrCode = showQrCode.Checked;
            newConfig.QrCodePos    = qrCodePos.SelectedIndex;
            if (int.TryParse(qrCodeAlpha.Text, out int _qrCodeAlpha))
            {
                newConfig.QrCodeAlpha = _qrCodeAlpha;
            }
            else
            {
                containError          = true;
                qrCodeAlpha.BackColor = Color.IndianRed;
            }
            if (int.TryParse(qrCodeSize.Text, out int _qrCodeSize))
            {
                newConfig.QrCodeSize = _qrCodeSize;
            }
            else
            {
                containError         = true;
                qrCodeSize.BackColor = Color.IndianRed;
            }
            if (int.TryParse(deltaTime.Text, out int _deltaTime))
            {
                newConfig.ChangePosDeltaTime = _deltaTime;
            }
            else
            {
                containError        = true;
                deltaTime.BackColor = Color.IndianRed;
            }
            if (containError)
            {
                MessageBox.Show("有错误的值,请修改后重新保存!");
                return;
            }
            string configJson = JsonConvert.SerializeObject(newConfig);

            loadedConfig = newConfig;
            File.WriteAllText(jsonFile, configJson);
            MessageBox.Show("将要发送并应用配置到所有计算机!", "提示");
            SendMessage(configJson, IPAddress.Broadcast);
        }