CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  VB.NET

继承PictureBox的用户控件上显示字符串的问题

楼主wzckr(随意)2005-07-22 20:42:51 在 .NET技术 / VB.NET 提问

我自建了一个继承PictureBox的用户控件,  
  代码如下:  
   
  Public   Class   ToolButton_ckr  
          Inherits   System.Windows.Forms.PictureBox  
   
  #Region   "   Windows   窗体设计器生成的代码   "  
  .........  
  .........  
  #End   Region  
   
          Private   Sub   ToolButton_ckr_Paint(ByVal   sender   As   Object,   ByVal   e   As   System.Windows.Forms.PaintEventArgs)   Handles   MyBase.Paint  
   
                  Dim   g   As   Graphics   =   Me.CreateGraphics  
                  Dim   d_titalFont   As   New   Font("宋体",   10,   FontStyle.Bold)  
                  g.DrawString("自建控件",   d_titalFont,   New   SolidBrush(Color.Black),   10,   10)  
   
          End   Sub  
   
  End   Class  
   
  可是在使用这个控件的时候运行时控件上没有出现“自建控件”这几个字,我把这个控件改成继承UserControl,运行时字符串是能正常显示的,可是我这个控件必须要继承PictureBox  
  哪位能帮我解决一下 问题点数:50、回复次数:7Top

1 楼bitsbird(一瓢 在路上...)回复于 2005-07-22 21:03:26 得分 30

Protected   Overloads   Overrides   Sub   OnPaint(ByVal   pe   As   PaintEventArgs)    
    MyBase.OnPaint(pe)    
    Dim   g   As   System.Drawing.Graphics   =   pe.Graphics    
    g.DrawString("自建控件",   New   Font("Tahoma",   12),   New   SolidBrush(Color.Red),   10,   10)    
  End   SubTop

2 楼HHLADN(I Want to exceed you)回复于 2005-07-22 21:22:21 得分 0

upTop

3 楼chendazhi(不务正业)回复于 2005-07-22 21:42:58 得分 0

二楼的方法不是一回事吗?Top

4 楼chendazhi(不务正业)回复于 2005-07-23 08:10:09 得分 10

Protected   Overloads   Overrides   Sub   OnPaint(ByVal   pe   As   PaintEventArgs)  
                  MyBase.OnPaint(pe)  
                  Dim   g   As   System.Drawing.Graphics   =   pe.Graphics  
                  Dim   d_titalFont   As   New   Font("宋体",   10,   FontStyle.Bold)  
                  g.DrawString("自建控件",   d_titalFont,   New   SolidBrush(Color.Black),   10,   10)  
          End   SubTop

5 楼chendazhi(不务正业)回复于 2005-07-23 08:17:26 得分 0

有人说说为什么  
          Private   Sub   ToolButton_ckr_Paint(ByVal   sender   As   Object,   ByVal   e   As   System.Windows.Forms.PaintEventArgs)   Handles   MyBase.Paint  
   
                  Dim   g   As   Graphics   =   Me.CreateGraphics  
                  Dim   d_titalFont   As   New   Font("宋体",   10,   FontStyle.Bold)  
                  g.DrawString("自建控件",   d_titalFont,   New   SolidBrush(Color.Black),   10,   10)  
   
          End   Sub  
   
   
  End   Class  
  不能显示,而  
  Protected   Overloads   Overrides   Sub   OnPaint(ByVal   pe   As   PaintEventArgs)  
                  Dim   g   As   System.Drawing.Graphics   =   pe.Graphics  
                  Dim   d_titalFont   As   New   Font("宋体",   10,   FontStyle.Bold)  
                  g.DrawString("自建控件",   d_titalFont,   New   SolidBrush(Color.Black),   10,   10)  
          End   Sub  
  能显示吗?  
  Top

6 楼AntingZ(夕惕若)回复于 2005-07-23 08:44:37 得分 10

不要用  
  Dim   g   As   Graphics   =   Me.CreateGraphics  
   
  应该用  
  Dim   g   As   Graphics   =   e.Graphics  
   
  @   chendazhi(不务正业-->何苦)    
    bitsbird(一瓢   闭关)的方法可以,因为用的是pe.Graphics,而不是   Me.CreateGraphics()Top

7 楼wzckr(随意)回复于 2005-07-23 09:12:12 得分 0

谢谢,用e.Graphics解决问题了Top

相关问题

  • 如何获得CEdit控件输入的字符串
  • CEdit控件内输出字符串如何控制换行?
  • 急!MSComm控件怎么发送字符串?
  • 怎样获得Edit控件里面的字符串
  • 如何从Memo控件获得所需字符串?(急)
  • 关于tmemo控件中的字符串的问题
  • 怎样把字符串当作控件的属性执行 ?
  • 怎么获取RichTextBox控件当前显示的字符串????
  • 如何将字符串作为一个控件来操作作???
  • spcomm控件,怎么向串口设备发送字符串?

关键词

  • 控件
  • 继承
  • picturebox
  • pe
  • graphics
  • byval
  • dim

得分解答快速导航

  • 帖主:wzckr
  • bitsbird
  • chendazhi
  • AntingZ

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo