/// <summary> /// 用默认设置初始化 CharmMessageBox 类的新实例 /// </summary> public CharmMessageBox() { InitializeComponent(); // 设置窗体阴影特效 APIOperation.FormBorderShadow(Handle); // * 设置双缓冲模式 * SetStyle(ControlStyles.AllPaintingInWmPaint | //不擦除背景 ,减少闪烁 ControlStyles.OptimizedDoubleBuffer | //双缓冲 ControlStyles.UserPaint, //使用自定义的重绘事件,减少闪烁 true); UpdateStyles(); // * 初始化属性 * TopMost = true; FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.CenterParent; Width = 350; mTitleColor = Color.White; mTextColor = Color.Black; // 创建控件集合 CharmControls = new List <CharmControl>(); // 创建用户按钮 mButtons = new CharmButton[3]; for (int i = 0; i < mButtons.Length; i++) { mButtons[i] = new CharmButton(); mButtons[i].ButtonType = ButtonType.Classic_Size_06922; mButtons[i].Visible = false; mButtons[i].MouseClick += new MouseEventHandler(ButtonMouseClick); CharmControls.Add(mButtons[i]); } // 创建检查框 mCheckBox = new CharmCheckBox(); mCheckBox.Visible = false; CharmControls.Add(mCheckBox); // 创建关闭按钮 CharmSysButton btnClose = new CharmSysButton(); btnClose.SysButtonType = SysButtonType.Close; btnClose.Location = new Point(Width - 46, 1); btnClose.MouseClick += new MouseEventHandler(btnClose_MouseClick); CharmControls.Add(btnClose); }
// 创建同步设置面板 private void CreateSyncSettingPanel() { // 创建同步目录文本框 CharmTextBox txtSyncDir = new CharmTextBox { Location = new Point(127 + MENU_WIDTH, 20 + TITLE_HEIGHT), Width = 260 }; // 创建浏览路径按钮 CharmButton btnViewPath = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "浏览路径", ForeColor = Color.DarkGreen, Location = new Point(399 + MENU_WIDTH, 22 + TITLE_HEIGHT) }; // 创建同步周期文本框 CharmTextBox txtSyncCycle = new CharmTextBox { Location = new Point(127 + MENU_WIDTH, 55 + TITLE_HEIGHT), Width = 50, TextInputMode = InputMode.Integer, MaxLength = 5, TextAlign = HorizontalAlignment.Center }; // 创建空间名称文本框 CharmTextBox txtBucket = new CharmTextBox { Location = new Point(290 + MENU_WIDTH, 55 + TITLE_HEIGHT), Width = 95, }; // 创建私有空间检查框 CharmCheckBox chkPrivateBucket = new CharmCheckBox { Location = new Point(400 + MENU_WIDTH, 57 + TITLE_HEIGHT), Text = "私有空间" }; // 创建同步前缀文本框 CharmTextBox txtPrefix = new CharmTextBox { Location = new Point(150 + MENU_WIDTH, 90 + TITLE_HEIGHT), Width = 95, }; // 创建监控变动检查框 CharmCheckBox chkCaptureChange = new CharmCheckBox { Location = new Point(260 + MENU_WIDTH, 92 + TITLE_HEIGHT), Text = "监控目录文件变化" }; // 创建立即同步按钮 CharmButton btnSyncNow = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "立即同步", ForeColor = Color.Purple, Location = new Point(399 + MENU_WIDTH, 92 + TITLE_HEIGHT) }; // 创建 AccessKey 文本框 CharmTextBox txtAccessKey = new CharmTextBox { Location = new Point(127 + MENU_WIDTH, 160 + TITLE_HEIGHT), Width = 260, TextInputMode = InputMode.Password }; // 创建查看 AccessKey 按钮 CharmButton btnViewAccessKey = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "查看密钥", ForeColor = Color.Red, Location = new Point(399 + MENU_WIDTH, 162 + TITLE_HEIGHT) }; // 创建 SecretKey 文本框 CharmTextBox txtSecretKey = new CharmTextBox { Location = new Point(127 + MENU_WIDTH, 195 + TITLE_HEIGHT), Width = 260, TextInputMode = InputMode.Password }; // 创建查看 SecretKey 按钮 CharmButton btnViewSecretKey = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "查看密钥", ForeColor = Color.Red, Location = new Point(399 + MENU_WIDTH, 197 + TITLE_HEIGHT) }; // 创建七牛开发平台链接标签 CharmLinkLabel lblQiniuOpen = new CharmLinkLabel { Location = new Point(280, 265), ForeColor = Color.Blue, Text = "七牛云存储开发者平台" }; // 关联控件事件 txtSyncDir.TextChanged += txtSyncDir_TextChanged; btnViewPath.MouseClick += btnViewPath_MouseClick; txtSyncCycle.TextChanged += txtSyncDir_TextChanged; txtBucket.TextChanged += txtSyncDir_TextChanged; chkPrivateBucket.MouseClick += chkPrivateBucket_MouseClick; lblQiniuOpen.MouseClick += lblQiniuOpen_MouseClick; txtAccessKey.TextChanged += txtSyncDir_TextChanged; btnViewAccessKey.MouseClick += btnViewAccessKey_MouseClick; txtSecretKey.TextChanged += txtSyncDir_TextChanged; btnViewSecretKey.MouseClick += btnViewSecretKey_MouseClick; txtPrefix.TextChanged += txtSyncDir_TextChanged; chkCaptureChange.MouseClick += chkPrivateBucket_MouseClick; btnSyncNow.MouseClick += btnSyncNow_MouseClick; // 将控件添加到集合中 this.Controls.Add(txtSyncDir); this.Controls.Add(txtSyncCycle); this.Controls.Add(txtAccessKey); this.Controls.Add(txtSecretKey); this.Controls.Add(txtBucket); this.Controls.Add(txtPrefix); // 创建同步设置面板控件集合 mSyncSettingControls = new List<Control> { txtSyncDir, txtSyncCycle, txtAccessKey, txtSecretKey, txtBucket, txtPrefix }; mSyncSettingCharmControls = new List<CharmControl> { btnViewPath, lblQiniuOpen, btnViewAccessKey, btnViewSecretKey, chkPrivateBucket, chkCaptureChange, btnSyncNow }; }
// 创建高级设置面板 private void CreateAdvancedSettingPanel() { // 创建重载过滤规则按钮 CharmButton btnReloadFilter = new CharmButton { ButtonType = ButtonType.Classic_Size_12425, Text = "重载过滤规则", ForeColor = Color.MediumPurple, Location = new Point(85 + MENU_WIDTH, 50 + TITLE_HEIGHT) }; // 创建过滤规则测试按钮 CharmButton btnTestFilter = new CharmButton { ButtonType = ButtonType.Classic_Size_12425, Text = "过滤规则测试", ForeColor = Color.MediumSlateBlue, Location = new Point(245 + MENU_WIDTH, 50 + TITLE_HEIGHT) }; // 关联控件事件 btnReloadFilter.MouseClick += btnReloadFilter_MouseClick; btnTestFilter.MouseClick += btnTestFilter_MouseClick; // 创建同步设置面板控件集合 mAdvancedSettingCharmControls = new List<CharmControl> { btnReloadFilter, btnTestFilter }; }
// 初始化设置 private void InitializeSetting() { // 设置窗体属性 this.Icon = Properties.Resources.icon; this.Text = APP_NAME; // 绘制窗体背景 DrawFormBackground(); // 初始化菜单栏 mMenuNames = new[] { "同步设置", "高级设置", "网络设置", "关于" }; #region 创建窗体组件 // 创建最小化系统按钮 CharmSysButton btnMin = new CharmSysButton { SysButtonType = SysButtonType.Minimum, ToolTipText = "最小化", Location = new Point(this.Width - 75, 1) }; // 创建关闭系统按钮 CharmSysButton btnClose = new CharmSysButton { SysButtonType = SysButtonType.Close, ToolTipText = "关闭", Location = new Point(this.Width - 44, 1) }; // 创建确定按钮 CharmButton btnMakeChange = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "确 定", Location = new Point(300, 430) }; // 创建取消按钮 CharmButton btnCancel = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "取 消", Location = new Point(390, 430) }; // 创建应用按钮 mBtnApply = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "应 用", Location = new Point(480, 430), Enabled = false }; // 创建控件集合 mCharmControls = new List<CharmControl> { btnMin, btnClose, btnMakeChange, btnCancel, mBtnApply }; // 关联控件事件 btnMin.MouseClick += btnMin_MouseClick; btnClose.MouseClick += btnClose_MouseClick; btnMakeChange.MouseClick += btnMakeChange_MouseClick; btnCancel.MouseClick += btnCancel_MouseClick; mBtnApply.MouseClick += mBtnApply_MouseClick; #endregion #region 创建主体区域 // 创建同步设置面板 CreateSyncSettingPanel(); // 创建高级设置面板 CreateAdvancedSettingPanel(); // 创建关于面板 CreateAboutPanel(); #endregion // 加载本地设置 LoadLocalSetting(); // 设置初始参数 if (!mIsHasKeys) mStatusText = "未填写密钥"; else if (!mIsVaildSyncDir) mStatusText = "无效的同步目录"; else mStatusText = "正在初始化..."; #region 创建菜单 // 创建托盘菜单 mTaryMenu = new CharmMenu(); mTaryMenu.AddItem("设置中心", MenuItemType.TextItem, new Bitmap(Properties.Resources.logo, 16, 16)); mTaryMenu.AddItem("打开同步目录", MenuItemType.TextItem); mTaryMenu.AddItem("", MenuItemType.Spliter); mTaryMenu.AddItem("立即同步", MenuItemType.TextItem); mTaryMenu.AddItem("", MenuItemType.Spliter); mTaryMenu.AddItem("关于", MenuItemType.TextItem); mTaryMenu.AddItem("退出", MenuItemType.TextItem); // 关联控件事件 mTaryMenu.MenuClick += mTaryMenu_MenuClick; #endregion #region 创建托盘图标 // 创建托盘图标 mNotifyIcon = new NotifyIcon { Icon = Properties.Resources.icon, Text = APP_NAME + "\n" + mStatusText, Visible = true }; // 关联控件事件 mNotifyIcon.MouseClick += mNotifyIcon_MouseClick; #endregion #region 创建服务线程 // 启动全局更新检查线程 Thread globalUpdateCheckThread = new Thread(GlobalUpdateCheck) { IsBackground = true }; globalUpdateCheckThread.Start(); #endregion }
/// <summary> /// 用默认设置初始化 CharmMessageBox 类的新实例 /// </summary> public CharmMessageBox() { InitializeComponent(); // 设置窗体阴影特效 APIOperation.FormBorderShadow(Handle); // * 设置双缓冲模式 * SetStyle(ControlStyles.AllPaintingInWmPaint | //不擦除背景 ,减少闪烁 ControlStyles.OptimizedDoubleBuffer | //双缓冲 ControlStyles.UserPaint, //使用自定义的重绘事件,减少闪烁 true); UpdateStyles(); // * 初始化属性 * TopMost = true; FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.CenterParent; Width = 350; mTitleColor = Color.White; mTextColor = Color.Black; // 创建控件集合 CharmControls = new List<CharmControl>(); // 创建用户按钮 mButtons = new CharmButton[3]; for (int i = 0; i < mButtons.Length; i++) { mButtons[i] = new CharmButton(); mButtons[i].ButtonType = ButtonType.Classic_Size_06922; mButtons[i].Visible = false; mButtons[i].MouseClick += new MouseEventHandler(ButtonMouseClick); CharmControls.Add(mButtons[i]); } // 创建检查框 mCheckBox = new CharmCheckBox(); mCheckBox.Visible = false; CharmControls.Add(mCheckBox); // 创建关闭按钮 CharmSysButton btnClose = new CharmSysButton(); btnClose.SysButtonType = SysButtonType.Close; btnClose.Location = new Point(Width - 46, 1); btnClose.MouseClick += new MouseEventHandler(btnClose_MouseClick); CharmControls.Add(btnClose); }
// 初始化设置 private void InitializeSetting() { // 设置窗体属性 this.Icon = Properties.Resources.icon; this.Text = "过滤规则测试"; // 绘制窗体背景 DrawFormBackground(); #region 创建窗体组件 // 创建关闭系统按钮 CharmSysButton btnClose = new CharmSysButton { SysButtonType = SysButtonType.Close, ToolTipText = "关闭", Location = new Point(this.Width - 44, 1) }; // 创建测试目录文本框 CharmTextBox txtTestDir = new CharmTextBox { Location = new Point(110, 10 + TITLE_HEIGHT), Width = 330 }; // 创建浏览路径按钮 CharmButton btnViewPath = new CharmButton { ButtonType = ButtonType.Classic_Size_08223, Text = "浏览路径", ForeColor = Color.DarkGreen, Location = new Point(455, 12 + TITLE_HEIGHT) }; // 创建测试规则按钮 CharmButton btnTest = new CharmButton { ButtonType = ButtonType.Classic_Size_12425, Text = "开始测试规则", ForeColor = Color.MediumSlateBlue, Location = new Point(420, 435), }; // 将控件添加到集合中 this.Controls.Add(txtTestDir); // 创建控件集合 mControls = new List<Control> { txtTestDir }; mCharmControls = new List<CharmControl> { btnClose, btnViewPath, btnTest }; // 关联控件事件 btnClose.MouseClick += btnClose_MouseClick; btnViewPath.MouseClick += btnViewPath_MouseClick; btnTest.MouseClick += btnTest_MouseClick; #endregion // 加载本地设置 LoadLocalSetting(); }