2016-12-22 1 views
0

저는 여기 새로 왔으며 단추로 직접 모양을 만드는 방법을 찾으려고합니다.나만의 단추 모양 만들기

클래스를 생성해야합니까? 또는 XML 파일? 테이블처럼 보일 버튼을 만들어야합니다. 나는이 코드를 발견했지만 그것을 만드는 것이 어렵다.

Button dynamicButton = new Button();   
// Define the points in the polygonal path. 
Point[] pts = { 
    new Point(20, 60), 
    new Point(140, 60), 
    new Point(140, 20), 
    new Point(220, 100), 
    new Point(140, 180), 
    new Point(140, 140), 
    new Point(20, 140) 
}; 

// Make the GraphicsPath. 
GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); 
polygon_path.AddPolygon(pts); 

// Convert the GraphicsPath into a Region. 
Region polygon_region = new Region(polygon_path); 

// Constrain the button to the region. 
dynamicButton.Region = polygon_region; 

// Make the button big enough to hold the whole region. 
dynamicButton.SetBounds(
    dynamicButton.Location.X, 
    dynamicButton.Location.Y, 
    pts[3].X + 5, pts[4].Y + 5); 
Controls.Add(dynamicButton); 
+3

(윈도우 폼, WPF는,는 GTK #은 ... 예를 들어)를 사용하고, 그래서 적절한 태그를 추가하십시오. –

+0

나는 GUI 툴킷을 모른다. 이 소프트웨어는 나이프로 전체 버튼을 그릴 수있는 외부 소프트웨어입니까? VS Blend에서 버튼을 만들어 winform으로 가져 오는 방법이 있습니까? – drs

+1

"GUI 툴킷을 모른다." - 창에 단추와 같은 시각적 요소를 추가하는 경우 GUI 툴킷을 사용하고 있습니다. 무엇을하기 전에 어떤 것을 사용하고 있는지 알아내는 것은 필수적입니다. "이것은 외부 소프트웨어인가?"- 아닙니다. "GUI 툴킷"은 그래픽 사용자 인터페이스 (즉, GUI)를 생성하는 데 사용될 수있는 임의의 시각 컴포넌트 세트에 대한 일반적인 용어이다. "VS Blend에서 버튼을 만들어 winform으로 가져 오기"- VS Blend는 Windows Forms와는 다른 GUI 툴킷 인 WPF를 대상으로합니다. 그들은 상호 작용할 수 있지만, 솔직히, 먼저 배워야 할 다른 것들이 있습니다. –

답변

0

C# WinForm 응용 프로그램에 대한 단추를 만들려고하는 경우 다음은 Panel 컨트롤을 사용하는 타원형 단추의 예제입니다. 사용자 정의 모양을 제공하려면 OnPain 이벤트에서 수행하십시오. 다음 코드를 사용해보십시오. 그러면 수행 할 작업을 파악할 수 있습니다.

using System; 
using System.Drawing; 
using System.Windows.Forms; 
using System.ComponentModel; 

public class AdonaiOvalButton : Panel 
{ 
    bool isControlActive = false; 

    #region Text 
    private string text = "Button"; 
    [NotifyParentProperty(true)] 
    [EditorBrowsable(EditorBrowsableState.Always)] 
    [Browsable(true)] 
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
    [Bindable(true)] 
    [Description("Sets the Text"), Category("Adonai")] 
    public override string Text 
    { 
     get { return text; } 
     set 
     { 
      if (value != text) 
      { 
       if (value == string.Empty) 
       { value = " "; } 
       text = value; 
       this.Invalidate(); 
      } 
     } 
    } 
    #endregion Text 

    #region ForeColor 
    private Color foreColor = Color.White; 
    [Description("Sets the Forecolor"), Category("Adonai")] 
    public override Color ForeColor 
    { 
     get { return foreColor; } 
     set 
     { 
      if (foreColor != value) 
      { 
       foreColor = value; 
       this.Invalidate(); 
      } 
     } 
    } 
    #endregion ForeColor 

    #region Outline Color 
    private Color outLineColor = Color.DarkGray; 
    [Description("Sets the Buttons outline color"), Category("Adonai")] 
    public Color OutLineColor 
    { 
     get { return outLineColor; } 
     set 
     { 
      if (outLineColor != value) 
      { 
       outLineColor = value; 
       this.Invalidate(); 
      } 
     } 
    } 
    #endregion Outline Color 

    #region Outline Width 
    private float outlineWidth = 0.4f; 
    [Description("Sets the Buttons outline width"), Category("Adonai")] 
    public float OutlineWidth 
    { 
     get { return outlineWidth; } 
     set 
     { 
      if (outlineWidth != value) 
      { 
       outlineWidth = value; 
       this.Invalidate(); 
      } 
     } 
    } 
    #endregion Outline Width 

    #region Default Back Color 
    //--Default Button Color--// 
    private Color inactiveColor = ControlPaint.Dark(SystemColors.Grad 
0

@Sinatr에 동의합니다. WPF가 더 쉬울 것입니다. 당신이 WPF로 이동하기로 결정하는 경우이 같은 뭔가를 할 수 :

<Button> 
    <Button.Template> 
     <ControlTemplate> 
      <Canvas Height="80" Width="100"> 
       <Rectangle Height="80" Width="100" Stroke="Blue" StrokeThickness="2"/> 
       <Line X1="50" Y1="0" X2="50" Y2="80" Stroke="Blue" StrokeThickness="2"/> 
       <Line X1="0" Y1="20" X2="100" Y2="20" Stroke="Blue" StrokeThickness="2"/> 
       <Line X1="0" Y1="40" X2="100" Y2="40" Stroke="Blue" StrokeThickness="1"/> 
       <Line X1="0" Y1="60" X2="100" Y2="60" Stroke="Blue" StrokeThickness="1"/> 
      </Canvas> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 
이 질문에 대한 답은 무겁게 GUI 툴킷에 따라
+0

어떻게이 XML 파일에서 읽을 수있는 버튼을 설정할 수 있습니까? – drs

+0

프로젝트를 만들 때 WPF 응용 프로그램을 만들어야합니다. 이렇게하면 mainwindow.xml 파일이 생성되어이 파일을 추가 할 수 있습니다. WPF 및 XAML에 대한 온라인 자습서가 많이 있지만 http://www.wpf-tutorial.com/xaml/what-is-xaml/에서 시작해 볼 수도 있습니다. – sclarke81