###前提・実現したいこと
塗りつぶした図形に枠線をつける
エクセルの[挿入][図形]で作成される図形を作成したい
よろしくお願いします。
###発生している問題・エラーメッセージ
塗りつぶした図形に対して線がかすれている等
三角形は、補正値を入れることで対応したが他の多角形や円も綺麗に描画できないかと
###該当のソースコード
C#
public Form1() { InitializeComponent(); // 図形描画用パネル Panel pZukei = new panel pZukei.BackColor = System.Drawing.Color.Lime; pZukei.Location = new System.Drawing.Point(39, 177); pZukei.Name = "userControl11"; pZukei.Size = new System.Drawing.Size(18, 18); pZukei.TabIndex = 9; pZukei.Visible = true; // 高さ変更用 TextBox txtH=new TextBox(); this.txtH.Location = new System.Drawing.Point(110, 12); this.txtH.Name = "txtH"; this.txtH.Size = new System.Drawing.Size(100, 19); this.txtH.TabIndex = 0; this.txtH.Text = "18"; this.txtH.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; TextBox txtW=new TextBox(); txtW.Location = new System.Drawing.Point(110, 37); txtW.Name = "txtW"; txtW.Size = new System.Drawing.Size(100, 19); txtW.TabIndex = 1; txtW.Text = "18"; txtW.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; Button button1 =new Button(); button1.Location = new System.Drawing.Point(234, 12); button1.Name = "button1"; button1.Size = new System.Drawing.Size(75, 23); button1.TabIndex = 2; button1.Text = "button1"; button1.UseVisualStyleBackColor = true; button1.Click += new System.EventHandler(this.button1_Click); this.Controls.Add(this.pZukei); this.Controls.Add(this.txtH); this.Controls.Add(this.txtW); this.Controls.Add(this.button1); } // 図形描写 private void button1_Click(object sender, EventArgs e) { pZukei.Size = new Size(int.Parse(txtW.Text), int.Parse(txtH.Text)); // パネルの形を図形に合わせる pZukei.Region = new Region(Sankaku(uZukei.Size)); pZukei.Refresh(); pZukei.BackgroundImage = gpLine(pZukei.Size); } // 図形描写 private GraphicsPath Sankaku(Size size) { GraphicsPath gPath = new GraphicsPath(); float fltWidth=0; float fltHeight = 0; float fltWidth2 = 0; float fltHeight2 = 0; PointF[] pntPos=new PointF[3];// 図形の点の位置 fltWidth = size.Width; fltHeight = size.Height; fltWidth2 = (float)(size.Width / 2.0); fltHeight2 = (float)(size.Height / 2.0); pntPos[0].X = 0; pntPos[0].Y = fltHeight; pntPos[1].X = fltWidth2; pntPos[1].Y = 0; pntPos[2].X = fltWidth; pntPos[2].Y = fltHeight; gPath.AddPolygon(pntPos); return gPath; } // 線描写 private Image gpLine(Size size) { //描画先とするImageオブジェクトを作成する PointF[] ptan = null; Bitmap canvas = new Bitmap(size.Width, size.Height); //ImageオブジェクトのGraphicsオブジェクトを作成する Graphics gPath = Graphics.FromImage(canvas); float fltWidth = 0; float fltHeight = 0; float fltWidth2 = 0; fltWidth = (float)size.Width - (float)1; fltHeight = (float)size.Height - (float)0.5; fltWidth2 = (float)(size.Width / 2.0);// 三角の上の横位置 ptan = new PointF[3]; //Penオブジェクトの作成(幅2黒色) Pen p = new Pen(Color.Black, 2); ptan[0].X = (float)0; ptan[0].Y = (float)size.Height ; ptan[1].X = (float)size.Width ; ptan[1].Y = (float)size.Height ; ptan[2].X = (float)size.Width / (float)2; ptan[2].Y = (float)0; gPath.DrawPolygon(p, ptan); //リソースを解放する gPath.Dispose(); //PictureBox1に表示する return canvas; }
###試したこと
それぞれの頂点の座標をずらすことを試したが
1図形に対して個々に調整が必要になります(図形の形、大きさ等)
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio 2008
C#にて作成
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/07 04:09