protected void LayoutComponent() { this.SuspendLayout(); float[] xOffset = m_sPrinterProperty.GetXOffset(); float[] yOffset = m_sPrinterProperty.get_YOffset(); for (int i = 0; i < m_nButtonNum; i++) { RadioButton radio = this.m_radioButtonPointer[i]; ControlClone.RadioButtonClone(radio, m_RadioButtonSample); //this.m_RadioButtonSample.Appearance = System.Windows.Forms.Appearance.Button; //this.m_RadioButtonSample.FlatStyle = System.Windows.Forms.FlatStyle.Flat; //this.m_RadioButtonSample.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; radio.Size = new Size(this.m_nButtonWidth, this.m_nButtonHeight); radio.Visible = true; radio.TabIndex = m_RadioButtonSample.TabIndex + i; radio.Tag = i; int groupIndex = i / m_sPrinterProperty.nColorNum; int colorIndex = i % m_sPrinterProperty.nColorNum; Point locate; if (m_bZeroSpace) { locate = new Point(this.Width - m_Margin - (int)(m_Scale * i) - this.m_nButtonWidth, this.m_nButtonHeight * groupIndex + m_Margin); } else { locate = new Point(this.Width - m_Margin - (int)(m_Scale * xOffset[i]) - this.m_nButtonWidth, (int)(m_Scale * yOffset[colorIndex]) + this.m_nButtonHeight * groupIndex + m_Margin); } if (m_bScaleMin_Y) { locate.X += m_MarginMiddle; } else { locate.Y += m_MarginMiddle; } radio.Location = locate; radio.BackColor = m_sPrinterProperty.GetButtonColor(colorIndex); //radio.Paint += new PaintEventHandler(m_radioButtonExample_Paint); radio.CheckedChanged += new System.EventHandler(this.m_RadioButtonSample_CheckedChanged); } }
private void LayoutFree(SPrinterProperty sPrinterProperty) { int nGroupNum = m_nButtonNum / m_sPrinterProperty.nColorNum; ///////////////////////////////////////////////////////////// ///Calculate max source width //////////////////////////////////////////////////////////// float fXoffsetMax = 0; float[] xOffset = sPrinterProperty.GetXOffset(); for (int i = 0; i < m_nButtonNum; i++) { if (fXoffsetMax < xOffset[i]) { fXoffsetMax = xOffset[i]; } } float fYoffsetMax = 0; float[] yOffset = sPrinterProperty.get_YOffset(); for (int i = 0; i < m_sPrinterProperty.nColorNum; i++) { if (fYoffsetMax < yOffset[i]) { fYoffsetMax = yOffset[i]; } } m_bZeroSpace = ((Math.Abs(fXoffsetMax) < 0.0001) && (Math.Abs(fYoffsetMax) < 0.0001)); //Assert Headheight:Headwidth = 1:4 //Assert Headheight == Two Head Space const int RatioHeightWidth = 3; //界面显示喷头的宽高比 float srcButtonHeight = Math.Abs(xOffset[1] - xOffset[0]); float srcButtonWidth = srcButtonHeight / RatioHeightWidth; double angle = m_sPrinterProperty.fHeadAngle * Math.PI / 180; float maxSrcWidth = (float)(fXoffsetMax + Math.Abs(srcButtonHeight * Math.Sin(angle) + srcButtonWidth * Math.Cos(angle))); float maxSrcHeight = fYoffsetMax + (float)((nGroupNum - 1) * srcButtonHeight + (Math.Abs(srcButtonHeight * Math.Cos(angle) + srcButtonWidth * Math.Sin(angle)))); ///////////////////////////////////////////////////////////// ///Calculate max source width //////////////////////////////////////////////////////////// int maxClientWidth = this.Width - m_Margin * 2; int maxClientHeight = this.Height - m_Margin * 2; if (m_bZeroSpace) { m_Scale = (float)(maxClientWidth - 1) / (m_nButtonNum); m_bScaleMin_Y = false; m_MarginMiddle = (int)(maxClientHeight - 1 - maxSrcHeight * m_Scale) / 2; m_nButtonHeight = (int)(m_Scale); m_nButtonWidth = (int )(m_nButtonHeight / 4); } else { float scaleX = ((float)(maxClientWidth - 1) / maxSrcWidth); float scaleY = ((float)(maxClientHeight - 1) / maxSrcHeight); m_Scale = Math.Min(scaleX, scaleY); if (m_Scale == scaleX) { m_bScaleMin_Y = false; m_MarginMiddle = (int)(maxClientHeight - 1 - maxSrcHeight * m_Scale) / 2; } else { m_bScaleMin_Y = true; m_MarginMiddle = (int)(maxClientWidth - 1 - maxSrcWidth * m_Scale) / 2; } //Modify Region m_nButtonHeight = (int)(srcButtonHeight * m_Scale); m_nButtonWidth = (int )(srcButtonWidth * m_Scale); } }