■ HorizBar 클래스의 MarksOnBar 속성을 사용해 막대 내 마크를 표시하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 수평 바 /// </summary> private HorizBar horizBar; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "HorizBar 클래스 : MarksOnBar 속성을 사용해 막대 내 마크 표시하기"; #region 스타일 콤보 박스를 설정한다. this.styleComboBox.DropDownStyle = ComboBoxStyle.DropDownList; this.styleComboBox.Items.Add("수평"); this.styleComboBox.Items.Add("수직"); this.styleComboBox.SelectedIndex = 0; #endregion #region 막대 내 표시 체크 박스를 설정한다. this.showMarkInBarCheckBox.Checked = true; #endregion #region 위치 콤보 박스를 설정한다. this.locationComboBox.DropDownStyle = ComboBoxStyle.DropDownList; this.locationComboBox.Items.Add(MarksLocation.Start ); this.locationComboBox.Items.Add(MarksLocation.Center); this.locationComboBox.Items.Add(MarksLocation.End ); this.locationComboBox.SelectedIndex = 2; #endregion #region 각도 숫자 UP/DOWN을 설정한다. this.angleNumericUpDown.TextAlign = HorizontalAlignment.Right; this.angleNumericUpDown.Minimum = 0; this.angleNumericUpDown.Value = 0; this.angleNumericUpDown.Maximum = 360; this.angleNumericUpDown.Increment = 90; #endregion #region 폰트 숫자 UP/DOWN을 설정한다. this.fontSizeNumericUpDown.TextAlign = HorizontalAlignment.Right; this.fontSizeNumericUpDown.Minimum = 1; this.fontSizeNumericUpDown.Value = 16; this.fontSizeNumericUpDown.Maximum = 100; #endregion #region 티차트를 설정한다. this.tChart.Panel.Pen = new ChartPen(Color.Black); #endregion #region 수평 바를 설정한다. this.horizBar = new HorizBar(); this.horizBar.BarStyle = BarStyles.RectGradient; this.horizBar.Brush.Color = Color.Red; this.horizBar.Brush.Solid = true; this.horizBar.Brush.Gradient.EndColor = Color.FromArgb(230, 200, 90 ); this.horizBar.Brush.Gradient.MiddleColor = Color.FromArgb(226, 242, 170); this.horizBar.Brush.Gradient.StartColor = Color.FromArgb(230, 200, 90 ); this.horizBar.Brush.Gradient.UseMiddle = true; this.horizBar.Brush.Gradient.Visible = true; this.horizBar.Brush.Visible = true; this.horizBar.Marks.AutoPosition = false; this.horizBar.MarksOnBar = true; this.horizBar.Marks.Transparent = true; this.horizBar.Marks.Font.Name = "Rage Italic"; this.horizBar.Marks.Font.Color = Color.Black; this.horizBar.Marks.Font.Bold = true; this.horizBar.Marks.Font.Size = 16; this.horizBar.FillSampleValues(5); this.tChart.Series.Add(this.horizBar); #endregion #region 이벤트를 설정한다. this.styleComboBox.SelectedIndexChanged += styleComboBox_SelectedIndexChanged; this.showMarkInBarCheckBox.CheckedChanged += showMarkInBarCheckBox_CheckedChanged; this.locationComboBox.SelectedIndexChanged += locationComboBox_SelectedIndexChanged; this.angleNumericUpDown.ValueChanged += angleNumericUpDown_ValueChanged; this.fontSizeNumericUpDown.ValueChanged += fontSizeNumericUpDown_ValueChanged; #endregion } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 스타일 콤보 박스 선택 인덱스 변경시 처리하기 - styleComboBox_SelectedIndexChanged(sender, e) /// <summary> /// 스타일 콤보 박스 선택 인덱스 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void styleComboBox_SelectedIndexChanged(object sender, EventArgs e) { Series series = this.tChart[0]; switch(this.styleComboBox.SelectedIndex) { case 0 : Series.ChangeType(ref series, typeof(HorizBar)); break; case 1 : Series.ChangeType(ref series, typeof(Bar )); break; } UpdateMarkLocation(); } #endregion #region 막대 내 표시 체크 박스 체크 변경시 처리하기 - showMarkInBarCheckBox_CheckedChanged(sender, e) /// <summary> /// 막대 내 표시 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void showMarkInBarCheckBox_CheckedChanged(object sender, EventArgs e) { (this.tChart[0] as CustomBar).MarksOnBar = this.showMarkInBarCheckBox.Checked; this.locationLabel.Enabled = this.showMarkInBarCheckBox.Enabled; this.locationComboBox.Enabled = this.showMarkInBarCheckBox.Checked; } #endregion #region 위치 콤보 박스 선택 인덱스 변경시 처리하기 - locationComboBox_SelectedIndexChanged(sender, e) /// <summary> /// 위치 콤보 박스 선택 인덱스 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void locationComboBox_SelectedIndexChanged(object sender, EventArgs e) { switch(this.locationComboBox.SelectedIndex) { case 0 : (this.tChart[0] as CustomBar).MarksLocation = MarksLocation.Start; break; case 1 : (this.tChart[0] as CustomBar).MarksLocation = MarksLocation.Center; break; case 2 : (this.tChart[0] as CustomBar).MarksLocation = MarksLocation.End; break; } } #endregion #region 각도 숫자 UP/DOWN 값 변경시 처리하기 - angleNumericUpDown_ValueChanged(sender, e) /// <summary> /// 각도 숫자 UP/DOWN 값 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void angleNumericUpDown_ValueChanged(object sender, EventArgs e) { this.tChart[0].Marks.Angle = (int)this.angleNumericUpDown.Value; } #endregion #region 폰트 크기 숫자 UP/DOWN 값 변경시 처리하기 - fontSizeNumericUpDown_ValueChanged(sender, e) /// <summary> /// 폰트 크기 숫자 UP/DOWN 값 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void fontSizeNumericUpDown_ValueChanged(object sender, EventArgs e) { this.tChart[0].Marks.Font.Size = (int)this.fontSizeNumericUpDown.Value; } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 마크 위치 업데이트하기 - UpdateMarkLocation() /// <summary> /// 마크 위치 업데이트하기 /// </summary> private void UpdateMarkLocation() { showMarkInBarCheckBox_CheckedChanged(null, null); } #endregion } } |