How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

08/03/2014

5 分钟可看完

本文内容

You can use the OvalShape control to draw circles or ovals on a form or container, both at design time and at run time. You can use the RectangleShape control to draw squares, rectangles, or rectangles with rounded corners on a form or container. You can also use this control to draw shapes both at design time and at run time.

You can customize the appearance of a shape by changing the width, color, and style of the border. The background of a shape is transparent by default; you can customize the background to display a solid color, a pattern, a gradient fill (transitioning from one color to another), or an image.

To draw a simple shape at design time

Drag the OvalShape or RectangleShape control from the Visual Basic PowerPacks tab (to install, see Visual Basic Power Packs Controls)in the Toolbox to a form or container control.

Drag the sizing and move handles to size and position the shape.

You can also size and position the shape by changing the Size and Position properties in the Properties window.

To create a rectangle with rounded corners, select the CornerRadius property in the Properties window and set it to a value that is greater than 0.

In the Properties window, optionally set additional properties to change the appearance of the shape.

To draw a simple shape at run time

On the Project menu, click Add Reference.

In the Add Reference dialog box, select Microsoft.VisualBasic.PowerPacks.VS, and then click OK.

In the Code Editor, add an Imports or using statement at the top of the module:

Imports Microsoft.VisualBasic.PowerPacks

using Microsoft.VisualBasic.PowerPacks;

Add the following code in an Event procedure:

Dim canvas As New ShapeContainer

' To draw an oval, substitute

' OvalShape for RectangleShape.

Dim theShape As New RectangleShape

' Set the form as the parent of the ShapeContainer.

canvas.Parent = Me

' Set the ShapeContainer as the parent of the Shape.

theShape.Parent = canvas

' Set the size of the shape.

theShape.Size = New System.Drawing.Size(200, 300)

' Set the location of the shape.

theShape.Location = New System.Drawing.Point(100, 100)

' To draw a rounded rectangle, add the following code:

theShape.CornerRadius = 12

ShapeContainer canvas = new ShapeContainer();

// To draw an oval, substitute

// OvalShape for RectangleShape.

RectangleShape theShape = new RectangleShape();

// Set the form as the parent of the ShapeContainer.

canvas.Parent = this;

// Set the ShapeContainer as the parent of the Shape.

theShape.Parent = canvas;

// Set the size of the shape.

theShape.Size = new System.Drawing.Size(200, 300);

// Set the location of the shape.

theShape.Location = new System.Drawing.Point(100, 100);

// To draw a rounded rectangle, add the following code:

theShape.CornerRadius = 12;

Customizing Shapes

When you use the default settings, the OvalShape and RectangleShape controls are displayed with a solid black border that is one pixel wide and a transparent background. You can change the width, style, and color of the border by setting properties. Additional properties enable you to change the background of a shape to a solid color, a pattern, a gradient fill, or an image.

Before you change the background of a shape, you should know how several of the properties interact.

The BackColor property setting has no effect unless the BackStyle property is set to Opaque.

If the FillStyle property is set to Solid, the FillColor overrides the BackColor.

If the FillStyle property is set to a pattern value such as Horizontal or Vertical, the pattern will be displayed in the FillColor. The background will be displayed in the BackColor, provided that the BackStyle property is set to Opaque.

In order to display a gradient fill, the FillStyle property must be set to Solid and the FillGradientStyle property must be set to a value other than None.

Setting the BackgroundImage property to an image overrides all other background settings.

To draw a circle that has a custom border

Drag the OvalShape control from the Visual Basic PowerPacks tab in the Toolbox to a form or container control.

In the Properties window, in the Size property, set Height and Width to equal values.

Set the BorderColor property to the color that you want.

Set the BorderStyle property to any value other than Solid.

Set the BorderWidth to the size that you want, in pixels.

To draw a circle that has a solid fill

Drag the OvalShape control from the Visual Basic PowerPacks tab in the Toolbox to a form or container control.

In the Properties window, in the Size property, set Height and Width to equal values.

Set the BackColor property to the color that you want.

Set the BackStyle property to Opaque.

To draw a circle that has a patterned fill

Drag the OvalShape control from the Visual Basic PowerPacks tab in the Toolbox to a form or container control.

In the Properties window, in the Size property, set Height and Width to equal values.

Set the BackColor property to the color that you want for the background.

Set the BackStyle property to Opaque.

Set the FillColor property to the color that you want for the pattern.

Set the FillStyle property to any value other than Transparent or Solid.

To draw a circle that has a gradient fill

Drag the OvalShape control from the Visual Basic PowerPacks tab in the Toolbox to a form or container control.

In the Properties window, in the Size property, set Height and Width to equal values.

Set the FillColor property to the color that you want for the starting color.

Set the FillGradientColor property to the color that you want for the ending color.

Set the FillGradientStyle property to a value other than None.

To draw a circle that is filled with an image

Drag the OvalShape control from the Visual Basic PowerPacks tab in the Toolbox to a form or container control.

In the Properties window, in the Size property, set Height and Width to equal values.

Select the BackgroundImage property and click the ellipsis button (...).

In the Select Resource dialog box, select an image to display. If no image resources are listed, click Import to browse to the location of an image.

Click OK to insert the image.

See Also

Tasks

Reference

Concepts

c#ovalshape_How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)相关推荐

  1. VC++使用画刷绘图 简单画刷 FillRect函数 位图画刷 透明画刷

    目录 使用画刷绘图 简单画刷 FillRect函数 位图画刷 透明画刷 接上:VC++ 利用MFC的CWindowDC类实现画线功能 在桌面窗口中画线 绘制彩色线条 CPen nPenStyle nW ...

  2. 学以致用——Java源码——使用随机几何图形制作屏保程序(Screen Saver with Shapes Using the Java 2D API)

    程序功能: 使用随机输出的几何图形作为屏保程序,用户可随时指定屏幕上要显示的图形元素的数量. 运行示例: 源码: 1. 实体类 import java.awt.Graphics; import jav ...

  3. 编码中统一更该变量的快捷键_更多项目想法,以提高您的编码技能

    编码中统一更该变量的快捷键 Two weeks ago I published an article containing 15 project ideas that you can build to ...

  4. java web开发初学_2018年学习Web开发的绝对初学者指南

    java web开发初学 This post was originally published on Coder-Coder.com. 该帖子最初发布在Coder-Coder.com上 . If yo ...

  5. 分享HTML5 canvas 的总结

    下面我贴出的是对 canvas 的一份总结 便于平时翻阅以及参考 canvas参考 <html><head><title>Canvas tutorial</t ...

  6. java多线程绘图_菜鸟学Java之 Java2D 多线程绘图

    1 绘制动态连线. 我需要在画布的两点间绘制一条可动态展示(连线可以一段段的按时间增长)的连线,于是我打算使用多线程进行绘制,于是我建立了一个自己的线程类: class MyThread implem ...

  7. OpenCV C++ 03 - Save an Image to a File

    Code /* 作者:郑大峰 时间:2019年09月20日 环境:OpenCV 4.1.1 + VS2017 内容:Save an Image to a File */#include "p ...

  8. OpenLayers 官网例子的中文详解

    当你希望实现某种功能的时候,即使你对 openlayers 几乎一窍不通,照着官网的例子做,也可以很快的实现想要的效果. 问题在于,官网的例子都是英文啊,不能很快定位到想要的效果是在哪个例子里面!!( ...

  9. opencv7-绘制形状和文字

    一.理论 二.代码演示 #include<opencv2\opencv.hpp> #include<iostream> #include<math.h> using ...

最新文章

  1. imagettftext php7,mac php7 imagettftext
  2. Oracle转Sqlserver 记录
  3. 如何理解typedef void
  4. 记录一次参加D2前端技术论坛的杭州之行
  5. yapi 权限_win10 x64下从0开始搭建YApi可视化接口管理平台
  6. 5复数与复变函数(五)
  7. [MySQL学习]Innodb锁相关描述翻译
  8. Java开发QQ机器人
  9. LGTM : code review 行话
  10. 黑科技网站推荐 第一弹 RemoveBg [一键抠图]
  11. 【更新】Excel控件Spire.XLS for .NET V7.12.90发布 | 支持向工作表添加形状
  12. 如何制作微信答题小程序(微信答题考试小程序开发制作功能介绍)
  13. coffeescript基本语法
  14. 利用python解决简单数独
  15. 关于ORA-01034和ORA-27101的一种解决方法
  16. python函数(八)-- 魔方方法
  17. RuntimeException和Exception区别
  18. vlookup函数使用说明
  19. 大清早的发现github凉凉了
  20. 南方CASS格式DWG的读取

热门文章

  1. jQuery查找标签--选择器,筛选器,模态对话框, 左侧菜单栏
  2. android学习笔记48——SQLite
  3. memcached的缺点
  4. python-文件操作(1)
  5. 【转】.NET试题总结二
  6. 用cloud-zoom做一个仿淘宝的宝贝放大镜查看功能
  7. Nhibernate+MVC开发日志
  8. 有段时间没更新了。。。放上我在做的东东的截图
  9. PotPlayer 64 bit快捷键大全
  10. Vuejs 插值操作