熟悉VS SDK开发的请帮我解决一个问题

还想懒够 还想懒够 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
当前我新建了一个基于Component类,并声明为IRootDesigner

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

如下图所示:




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

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

以下附基于Component类的代码:

1. DesignPanel

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
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
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的,就可以看到设计时面板的状况了


谢谢!
...全文

相关推荐

帮VS2019 找回丢失的 SDK问题

### VS2019 编译 C++ 工程时丢失 SDK 问题解析#### 问题背景在使用 Visual Studio 2019 (VS2019) 编译 C++ 工程时,遇到了一个较为常见的问题:编译过程中报告无法找到特定版本的

weixin_38651661

VS2015配置海康威视工业相机SDK二次开发

1、概述:工业相机SDK是用于控制相机的一个独立组件,支持获取实时图像数据、配置参数、对图像进行后续处理等功能。工业相机SDK兼容GigE Vision协议、USB3 Vision协议、Camera Link协议、CoaXPress协议,目前支持Windows、Linux、Mac以及Android系统,不同的操作系统下需要加载使用配套的SDK版本并参考相应SDK开发指南。SDK对相机的控制上,最...

威海云博客

VS的SDK切换工具

总结起来,“VS的SDK切换工具”是解决低版本Visual Studio与高版本SDK兼容性问题的有效手段,它简化了版本管理,让开发者能够在不升级整个IDE的情况下,充分利用新SDK的功能。

wuqian_6

解决安装vs2019后原vs2017项目无法编译各种报错的问题

开发者需要根据项目的实际需求,确保在安装过程中勾选了所有必要的组件,比如C++构建工具、特定的SDK或库等。

weixin_38736529

配置Qt使用VS2010进行开发安装以及问题解决方法

"Qt 使用 VS2010 进行开发安装配置与问题解决方法"在本文中,我们将详细介绍如何配置 Qt 使用 VS2010 进行开发,包括安装 Qt SDK、安装 VS2010 的 Qt 插件、编译 Qt、

小草丫
评论 25
收藏 已收藏
分享
返回顶部
还想懒够
C# 111,128 成员 642,536 内容