C#中如何实现如下图片显示功能

csandcs 2017-02-10 05:50:14

如图所示,要求在windows窗体上显示上图,并且加斜线的那个图的长度和宽度可以随着参数的变化而变化,这个功能如何实现?
...全文
664 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
csandcs 2017-02-15
  • 打赏
  • 举报
回复
引用 13 楼 mjp1234airen4385 的回复:
要么多边形绘图,要么绘两个图,叠加到以前就行。
已经采用多边形绘图实现了,谢谢。
crystal_lz 2017-02-13
  • 打赏
  • 举报
回复
Grahpics.DrawXXXX 有很多绘图函数 根据自己的情况选择。 。。
mjp1234airen4385 2017-02-13
  • 打赏
  • 举报
回复
要么多边形绘图,要么绘两个图,叠加到以前就行。
  • 打赏
  • 举报
回复
如果你的问题是不会用某个画线语句来画线,或者不知道几何知识表示,那么开另外一个帖子。从简单的1+2=3问题开始学习。
  • 打赏
  • 举报
回复
引用 8 楼 csandcs 的回复:
我给的这个图形是在左下角缺个小三角形,还有个图是在右下角多个小三角形,请问这个怎么实现?
贴出你的代码。
csandcs 2017-02-11
  • 打赏
  • 举报
回复
引用 9 楼 qq_36769535 的回复:
是这种效果么?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dm_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
        {
            int span = 2;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
            if (cusp)
            {
                span = 10;
                PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
                PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
                PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
                PointF[] ptsArray = { p1, p2, p3 };
                g.FillPolygon(myLinearGradientBrush, ptsArray);
            }
            g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
        }
        public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
        {
            GraphicsPath gp = new GraphicsPath();
            gp.AddArc(x, y, radius, radius, 180, 90);
            gp.AddArc(width - radius, y, radius, radius, 270, 90);
            gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
            gp.AddArc(x, height - radius, radius, radius, 90, 90);
            gp.CloseAllFigures();
            return gp;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Draw(e.ClipRectangle, e.Graphics, 18, true, Color.FromArgb(90, 143, 0), Color.FromArgb(41, 67, 0));
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.DrawString("我是个Panel", new Font("微软雅黑", 20, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {
            Draw(e.ClipRectangle, e.Graphics, 18, true, Color.FromArgb(0, 122, 204), Color.FromArgb(8, 39, 57));
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.DrawString("我是个大大的Panel", new Font("微软雅黑", 20, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
        }
    }
}

非常感谢,虽然跟我想要的模型形状还差一些,但是提供了很好的思路,我模仿一下看看能不能做出来。再一次谢谢。
qq_36769535 2017-02-10
  • 打赏
  • 举报
回复
是这种效果么?



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dm_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
{
int span = 2;
g.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
if (cusp)
{
span = 10;
PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
PointF[] ptsArray = { p1, p2, p3 };
g.FillPolygon(myLinearGradientBrush, ptsArray);
}
g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
GraphicsPath gp = new GraphicsPath();
gp.AddArc(x, y, radius, radius, 180, 90);
gp.AddArc(width - radius, y, radius, radius, 270, 90);
gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
gp.AddArc(x, height - radius, radius, radius, 90, 90);
gp.CloseAllFigures();
return gp;
}

private void panel1_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18, true, Color.FromArgb(90, 143, 0), Color.FromArgb(41, 67, 0));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("我是个Panel", new Font("微软雅黑", 20, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
}

private void panel2_Paint(object sender, PaintEventArgs e)
{
Draw(e.ClipRectangle, e.Graphics, 18, true, Color.FromArgb(0, 122, 204), Color.FromArgb(8, 39, 57));
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawString("我是个大大的Panel", new Font("微软雅黑", 20, FontStyle.Regular), new SolidBrush(Color.White), new PointF(10, 10));
}
}
}

csandcs 2017-02-10
  • 打赏
  • 举报
回复
引用 7 楼 csandcs 的回复:
[quote=引用 5 楼 yuankaiwsl 的回复:] 假设你在TextBox里输入阴影部分长宽,先定义长和宽的全局变量,在TextBox的TextChanged事件里给变量赋值,并调用Refresh,在窗体的Paint事件里根据变量画矩形就行了
你好,根据你的指导,我画出来了矩形,但是我的图形不是标准的矩形,在矩形的右下角还有个小三角形,这个怎么实现?另外怎么保证矩形的长和宽变化了,这个小三角形与矩形右下角的相对位置始终保持不变?谢谢。[/quote] 我给的这个图形是在左下角缺个小三角形,还有个图是在右下角多个小三角形,请问这个怎么实现?
csandcs 2017-02-10
  • 打赏
  • 举报
回复
引用 5 楼 yuankaiwsl 的回复:
假设你在TextBox里输入阴影部分长宽,先定义长和宽的全局变量,在TextBox的TextChanged事件里给变量赋值,并调用Refresh,在窗体的Paint事件里根据变量画矩形就行了


你好,根据你的指导,我画出来了矩形,但是我的图形不是标准的矩形,在矩形的右下角还有个小三角形,这个怎么实现?另外怎么保证矩形的长和宽变化了,这个小三角形与矩形右下角的相对位置始终保持不变?谢谢。
csandcs 2017-02-10
  • 打赏
  • 举报
回复
引用 5 楼 yuankaiwsl 的回复:
假设你在TextBox里输入阴影部分长宽,先定义长和宽的全局变量,在TextBox的TextChanged事件里给变量赋值,并调用Refresh,在窗体的Paint事件里根据变量画矩形就行了
明白你的意思,但是不会写代码,能给点代码提示下吗?新手编程,谢谢。
巴士上的邂逅 2017-02-10
  • 打赏
  • 举报
回复
假设你在TextBox里输入阴影部分长宽,先定义长和宽的全局变量,在TextBox的TextChanged事件里给变量赋值,并调用Refresh,在窗体的Paint事件里根据变量画矩形就行了
csandcs 2017-02-10
  • 打赏
  • 举报
回复
引用 2 楼 penglan_ 的回复:
你想问啥,看不懂你的提问
我想做个动态显示图片的,就像图中那样的图片,但是图中画斜线的两个矩形能够根据我输入的参数动态的改变长和宽。
csandcs 2017-02-10
  • 打赏
  • 举报
回复
引用 1 楼 yuankaiwsl 的回复:
可以用gdi+画
您好,请问怎么根据输入的长宽参数动态的改变图中画斜线的部分的长和宽呢?
penglan_ 2017-02-10
  • 打赏
  • 举报
回复
你想问啥,看不懂你的提问
巴士上的邂逅 2017-02-10
  • 打赏
  • 举报
回复
可以用gdi+画

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧