📄 posctrl.cs
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using KTDictSeg;
namespace PosDisplayCtrl
{
public partial class PosCtrl : UserControl
{
const int POS_PER_LINE = 4;
const int POS_TOP = 0;
const int POS_LEFT = 0;
const int POS_WIDTH = 120;
const int POS_HIGHT = 30;
Hashtable m_PosTable = new Hashtable();
int m_Pos = 0;
public int Pos
{
get
{
RefreshPos();
return m_Pos;
}
set
{
m_Pos = value;
Display();
}
}
private void CreatePosCheckBox()
{
int pos = 0x40000000;
this.Width = POS_PER_LINE * POS_WIDTH;
this.Height = POS_HIGHT * (32 / POS_PER_LINE + 1);
int j = POS_TOP;
for (int i = 0; i < 31; i++)
{
if (i % POS_PER_LINE == 0)
{
j += POS_HIGHT;
}
if (pos == 1)
{
pos = 0;
}
T_POS tPos = (T_POS)pos;
CheckBox checkBoxPos = new CheckBox();
checkBoxPos.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
m_PosTable[tPos] = checkBoxPos;
checkBoxPos.Tag = tPos;
checkBoxPos.Parent = this;
checkBoxPos.Name = tPos.ToString();
checkBoxPos.Text = CPOS.GetChsPos(tPos);
checkBoxPos.Top = j;
checkBoxPos.Width = POS_WIDTH;
checkBoxPos.Left = POS_LEFT + POS_WIDTH * (i % POS_PER_LINE);
pos >>= 1;
}
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
if (checkBox.Checked)
{
checkBox.ForeColor = Color.Red;
CheckBox posCheckBox = (CheckBox)m_PosTable[(T_POS)0];
if ((T_POS)checkBox.Tag == T_POS.POS_UNK)
{
foreach (object key in m_PosTable.Keys)
{
posCheckBox = (CheckBox)m_PosTable[key];
if ((T_POS)posCheckBox.Tag == T_POS.POS_UNK)
{
continue;
}
posCheckBox.Checked = false;
}
}
else
{
posCheckBox.Checked = false;
}
}
else
{
checkBox.ForeColor = Color.Black;
}
}
private void RefreshPos()
{
CheckBox posCheckBox;
posCheckBox = (CheckBox)m_PosTable[(T_POS)0];
m_Pos = 0;
int pos = 0x40000000;
for (int i = 0; i < 30; i++)
{
T_POS tPos = (T_POS)pos;
posCheckBox = (CheckBox)m_PosTable[tPos];
if (posCheckBox.Checked)
{
m_Pos |= pos;
}
pos >>= 1;
}
}
private void Display()
{
CheckBox posCheckBox;
posCheckBox = (CheckBox)m_PosTable[(T_POS)0];
if (m_Pos == 0)
{
foreach(object key in m_PosTable.Keys)
{
((CheckBox)m_PosTable[key]).Checked = false;
}
posCheckBox = (CheckBox)m_PosTable[(T_POS)0];
posCheckBox.Checked = true;
return;
}
else
{
posCheckBox.Checked = false;
}
int pos = 0x40000000;
for (int i = 0; i < 30; i++)
{
T_POS tPos = (T_POS)pos;
posCheckBox = (CheckBox)m_PosTable[tPos];
if ((m_Pos & pos) != 0)
{
posCheckBox.Checked = true;
}
else
{
posCheckBox.Checked = false;
}
pos >>= 1;
}
}
public PosCtrl()
{
InitializeComponent();
CreatePosCheckBox();
Display();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -