vb.net能否自定义一下控件继承webbrowser控件?

highscore2 2009-03-12 11:42:45
vb.net能否自定义一下控件继承webbrowser控件?
...全文
146 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuwt2008 2010-12-15
  • 打赏
  • 举报
回复
问题是WebBrowser类已经被密封(sealed)了,无法继承
未知 WebBrowser 继承自哪个类,添加了哪些功能,微软为什么要sealed?
jyoeiei 2009-06-02
  • 打赏
  • 举报
回复
这是我做的只可以输入数字的DataGridView列
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing.Design

Public Class DgvNumberTextBoxCell
Inherits DataGridViewTextBoxCell

Private _mask As String
Private _promptChar As Char
Private _includePrompt As DataGridViewTriState
Private _includeLiterals As DataGridViewTriState
Private _validatingType As Type
Private _numberLength As Integer
Private _xiaoshuLength As Integer

Public Sub New()
mask = ""
promptChar = "_"c
includePrompt = DataGridViewTriState.NotSet
includeLiterals = DataGridViewTriState.NotSet
validatingType = GetType(String)
End Sub

''' <summary>
''' 编辑在用户编辑单元格时
''' </summary>
''' <param name="rowIndex">当前行</param>
''' <param name="initialFormattedValue">值</param>
''' <param name="dataGridViewCellStyle">Cell样式</param>
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)

MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
Dim maskedTextBoxEditing As DgvNumberTextBoxControl = DataGridView.EditingControl

'设置MaskedTextBox特性
Dim dgvColumn As DataGridViewColumn = OwningColumn
If TypeOf (dgvColumn) Is DgvNumberTextBoxColumn Then
'if (dgvColumn is DataGridViewMaskedTextBoxColumn)
Dim maskedTextBoxColumn As DgvNumberTextBoxColumn = dgvColumn
If (String.IsNullOrEmpty(Mask)) Then
maskedTextBoxEditing.Mask = maskedTextBoxColumn.Mask
Else
maskedTextBoxEditing.Mask = Mask
End If
'提示字符
maskedTextBoxEditing.PromptChar = PromptChar
If ValidatingType Is Nothing Then
maskedTextBoxEditing.ValidatingType = maskedTextBoxColumn.ValidatingType
Else
maskedTextBoxEditing.ValidatingType = ValidatingType
End If
If Me.Value Is Nothing Then
maskedTextBoxEditing.Text = ""
Else
maskedTextBoxEditing.Text = Me.Value.ToString
End If
End If

End Sub

''' <summary>
''' 设置编辑状态单元格类型
''' </summary>
Public Overrides ReadOnly Property EditType() As Type
Get
Return GetType(DgvNumberTextBoxControl)
End Get
End Property

''' <summary>
''' 设置正则表达式
''' </summary>
Public Overridable Property Mask() As String
Get
Return _mask
End Get
Set(ByVal value As String)
_mask = value
End Set
End Property

''' <summary>
''' 用于提示用户进行输入的字符。默认为下划线 (_)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>提示字符位于尚未赋予输入值的可编辑位置</remarks>
Public Overridable Property PromptChar() As Char
Get
Return _promptChar
End Get
Set(ByVal value As Char)
_promptChar = value
End Set
End Property

''' <summary>
''' 获取或设置一个值,该值指示当显示带格式的字符串时是否使用 PromptChar 来表示缺少的用户输入
''' </summary>
Public Overridable Property IncludePrompt() As DataGridViewTriState
Get
Return _includePrompt
End Get
Set(ByVal value As DataGridViewTriState)
_includePrompt = value
End Set
End Property

''' <summary>
''' 获取或设置一个值,该值指示输入掩码中的原义字符是否应包含在带格式的字符串中
''' </summary>
Public Overridable Property IncludeLiterals() As DataGridViewTriState
Get
Return _includeLiterals
End Get
Set(ByVal value As DataGridViewTriState)
_includeLiterals = value
End Set
End Property

''' <summary>
''' 验证类型
''' </summary>
Public Overridable Property ValidatingType() As Type
Get
Return _validatingType
End Get
Set(ByVal value As Type)
_validatingType = value
End Set
End Property

''' <summary>
''' 输入数字长度
''' </summary>
Public Overridable Property NumberLength() As Integer
Get
Return _numberLength
End Get
Set(ByVal value As Integer)
_numberLength = value
End Set
End Property

''' <summary>
''' 小数数字长度
''' </summary>
Public Overridable Property XiaoshuLength() As Integer
Get
Return _xiaoshuLength
End Get
Set(ByVal value As Integer)
_xiaoshuLength = value
End Set
End Property

End Class
highscore2 2009-05-12
  • 打赏
  • 举报
回复
如何重写,贴一下代码马上结贴,谢谢
xue1234567890 2009-03-23
  • 打赏
  • 举报
回复
一样的道理呀..
重写textbox一样的道理呀..
jyoeiei 2009-03-23
  • 打赏
  • 举报
回复
winform的TextBox和combox我继承,重写过。
webbrowser就不知道了!应该也可以的。
highscore2 2009-03-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 oyljerry 的回复:]
可以自己实现一个控件,里面再封装webbrowser控件
[/Quote]
但这样多了一层,用起来不方便, 我本来只要在completed 及 navigate 必须执行一些函数,现在每次需要使用控件时都必须自己添加上去,不方便. 我想要的就是:好象继承class一样方便,我可以在原class的基础上,override 一些函数,这样做有什么好处我相信大家都明白
oyljerry 2009-03-12
  • 打赏
  • 举报
回复
可以自己实现一个控件,里面再封装webbrowser控件
highscore2 2009-03-12
  • 打赏
  • 举报
回复
vb.net能否自定义一个控件继承webbrowser控件? 主要是多个地方用了多个webbrowser 控件, 但需要在每个控件的某些事件绑定执行某些函数, 现在每次向窗口上添加一人webbrowser控件都需要把相同的代码加到控件上,很不方便,如果能自己定义一个控件继承webbrowser控件并封装一些自己的代码,那么,就可以省去很多工作.

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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