读书人

熟悉VS SDK开发的请帮小弟我解决一个有

发布时间: 2012-04-08 14:38:30 作者: rapoo

熟悉VS SDK开发的请帮我解决一个问题
当前我新建了一个基于Component类,并声明为IRootDesigner

现在出现的效果就是在VS设计模式时,可以出现一个带点的面板(那些点都是自己用双缓冲+GDI画的)

如下图所示:




现在出现的情况就是我想在设计面板中点击鼠标右键,弹出菜单后出现“查看代码”“粘贴”“属性”等操作,类似于WinForm设计时右键菜单。请问该如何实现。

注:现在我已安装好VS SDK 2008 SP1

以下附基于Component类的代码:

1. DesignPanel

C# code
using System;using System.Collections.Generic;using System.Text;using System.ComponentModel;using System.ComponentModel.Design;using System.Windows.Forms;namespace eWhereThink.Workflow.Design{    [Designer(typeof(DesignPanelDesigner), typeof(IRootDesigner))]    [Designer(typeof(ComponentDesigner))]    [ToolboxItem(false)]    public class DesignPanel : Component    {        public DesignPanel()        {        }    }}


2. DesignPanelDesigner
C# code
using System;using System.Collections.Generic;using System.Text;using System.ComponentModel.Design;using System.Drawing.Design;using System.ComponentModel;using System.Windows.Forms;using System.Windows.Forms.Design;namespace eWhereThink.Workflow.Design{    public class DesignPanelDesigner : ComponentDocumentDesigner, IRootDesigner    {        DesignControl _rootViewControl;        public DesignPanelDesigner()        {                    }        public object GetView(ViewTechnology technology)        {            _rootViewControl = new DesignControl(this);            return _rootViewControl;        }        public ViewTechnology[] SupportedTechnologies        {            get            {                return new ViewTechnology[] { ViewTechnology.Default };            }        }        protected override bool GetToolSupported(ToolboxItem tool)        {            MessageBox.Show(tool.TypeName);            return true;        }        public void ToolPicked(ToolboxItem tool)        {            MessageBox.Show(tool.TypeName + "     ToolPicked");        }    }}


3. DesignControl
C# code
using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Collections;using System.Drawing;using System.Drawing.Drawing2D;using System.ComponentModel;namespace eWhereThink.Workflow.Design{    [ToolboxItem(false)]    public class DesignControl : ScrollableControl    {        private DesignPanelDesigner _rootDesigner;        private IContainer components;        private Hashtable _componentInfoTable;        public DesignControl(DesignPanelDesigner rootDesigner)        {            InitializeComponent();            _rootDesigner = rootDesigner;            _componentInfoTable = new Hashtable();            SetStyle(ControlStyles.AllPaintingInWmPaint, true);            SetStyle(ControlStyles.UserPaint, true);            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);            SetStyle(ControlStyles.ResizeRedraw, true);            this.Invalidate();        }        private void InitializeComponent()        {            this.SuspendLayout();            //             // DesignControl            //             this.Paint += new System.Windows.Forms.PaintEventHandler(this.DesignControl_Paint);            this.ResumeLayout(false);        }        private void DesignControl_Paint(object sender, PaintEventArgs e)        {            float fZoom = 1F;            Size size = new Size();            size.Width = Math.Max(this.Width, this.AutoScrollMinSize.Width);            size.Height = Math.Max(this.Height, this.AutoScrollMinSize.Height);            Bitmap bmp = new Bitmap(size.Width, size.Height);            Graphics g = Graphics.FromImage(bmp);            Color selectColor = Color.FromArgb(102, 102, 255);            Brush selectBrush = new SolidBrush(selectColor);            try            {                g.SmoothingMode = SmoothingMode.HighQuality; //高质量                g.PixelOffsetMode = PixelOffsetMode.HighQuality; //高像素偏移质量                //画点                for (int iX = (int)(10 * fZoom); iX < bmp.Width; iX += (int)(10 * fZoom))                {                    for (int iY = (int)(10 * fZoom); iY < bmp.Height; iY += (int)(10 * fZoom))                    {                        bmp.SetPixel(iX, iY, Color.Black);                    }                }                e.Graphics.DrawImage(bmp, 0 - this.HorizontalScroll.Value, 0 - this.VerticalScroll.Value);            }            catch (Exception err)            {                MessageBox.Show(err.Message);            }            finally            {                selectBrush.Dispose();                g.Dispose();                bmp.Dispose();            }        }    }} 




如果新建一个类是继承于DesignPanel的,就可以看到设计时面板的状况了


谢谢!

[解决办法]
我想知道红色标题是怎么发出来的。。。
[解决办法]
有点不明白,你自己的组件,拖放到ide中,不是就有那些菜单了吗
[解决办法]
真不懂,关注
[解决办法]
学习。。。。说真的 这个VS最笨的拖控件不就行了嘛 怎么出现这么奇怪的。。。。不明白
[解决办法]
这个是不是在给VS增加功能啊,不知道意义何在。
[解决办法]
关注一下
[解决办法]
<strong><font color="red">[发红色字看一下源代码不知道了]</font></strong>
[解决办法]
探讨
我想知道红色标题是怎么发出来的。。。

[解决办法]
想看看最后的[解决方案] 如何?
有看楼主贴出代码。

读书人网 >C#

热点推荐