不带项目名称的VB.NET导入
我的表单只有在使用不带项目名称的VB.NET导入,vb.net,class,namespaces,Vb.net,Class,Namespaces,我的表单只有在使用 Imports WindowsApplication1.FrameGrabber Imports FrameGrabber 但当我使用 Imports WindowsApplication1.FrameGrabber Imports FrameGrabber 我将在几个不同的项目中使用FrameGrabber,因此我更愿意只说“Imports FrameGrabber” 我的“FrameGrabber/CameraWindow”定义如下: Imports System
Imports WindowsApplication1.FrameGrabber
Imports FrameGrabber
但当我使用
Imports WindowsApplication1.FrameGrabber
Imports FrameGrabber
我将在几个不同的项目中使用FrameGrabber,因此我更愿意只说“Imports FrameGrabber”
我的“FrameGrabber/CameraWindow”定义如下:
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Windows.Forms
Imports System.Threading
Namespace FrameGrabber
''' <summary>
''' Summary description for CameraWindow.
''' </summary>
Public Class CameraWindow
Inherits System.Windows.Forms.Control
Private m_camera As Camera = Nothing
Private m_autosize As Boolean = False
Private needSizeUpdate As Boolean = False
Private firstFrame As Boolean = True
' AutoSize property
<DefaultValue(False)> _
Public Overrides Property AutoSize() As Boolean
Get
Return m_autosize
End Get
Set(value As Boolean)
m_autosize = value
UpdatePosition()
End Set
End Property
' Camera property
<Browsable(False)> _
Public Property Camera() As Camera
Get
Return m_camera
End Get
Set(value As Camera)
' lock
Monitor.Enter(Me)
' detach event
If m_camera IsNot Nothing Then
RemoveHandler m_camera.NewFrame, AddressOf Me.pCameraWindow_NewFrame
End If
m_camera = value
needSizeUpdate = True
firstFrame = True
' atach event
If m_camera IsNot Nothing Then
AddHandler m_camera.NewFrame, AddressOf Me.pCameraWindow_NewFrame
End If
' unlock
Monitor.[Exit](Me)
End Set
End Property
' Constructor
Public Sub New()
InitializeComponent()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
End Sub
#Region "Windows Form Designer generated code"
Private Sub InitializeComponent()
Me.SuspendLayout()
Me.ResumeLayout(False)
End Sub
#End Region
' Paint control
Protected Overrides Sub OnPaint(pe As PaintEventArgs)
If (needSizeUpdate) OrElse (firstFrame) Then
UpdatePosition()
needSizeUpdate = False
End If
' lock
Monitor.Enter(Me)
Dim g As Graphics = pe.Graphics
Dim rc As Rectangle = Me.ClientRectangle
If m_camera IsNot Nothing Then
Try
m_camera.Lock()
' draw frame
If m_camera.LastFrame IsNot Nothing Then
g.DrawImage(m_camera.LastFrame, rc.X + 1, rc.Y + 1, rc.Width - 2, rc.Height - 2)
firstFrame = False
Else
' Create font and brush
Dim drawFont As New Font("Arial", 12)
Dim drawBrush As New SolidBrush(Color.White)
g.DrawString("Connecting ...", drawFont, drawBrush, New System.Drawing.PointF(5, 5))
drawBrush.Dispose()
drawFont.Dispose()
End If
Catch generatedExceptionName As Exception
Finally
m_camera.Unlock()
End Try
End If
' unlock
Monitor.[Exit](Me)
MyBase.OnPaint(pe)
End Sub
Public Function getImage() As Image
If Not m_camera Is Nothing Then
If Not m_camera.LastFrame Is Nothing Then
Return m_camera.LastFrame
End If
End If
Return Nothing
End Function
' Update position and size of the control
Public Sub UpdatePosition()
' lock
Monitor.Enter(Me)
If (m_autosize) AndAlso (Me.Parent IsNot Nothing) Then
Dim rc As Rectangle = Me.Parent.ClientRectangle
Dim width As Integer = 320
Dim height As Integer = 240
If m_camera IsNot Nothing Then
m_camera.Lock()
' get frame dimension
If m_camera.LastFrame IsNot Nothing Then
width = m_camera.LastFrame.Width
height = m_camera.LastFrame.Height
End If
m_camera.Unlock()
End If
'
Me.SuspendLayout()
Me.Location = New Point((rc.Width - width - 2) \ 2, (rc.Height - height - 2) \ 2)
Me.Size = New Size(width + 2, height + 2)
Me.ResumeLayout()
End If
' unlock
Monitor.[Exit](Me)
End Sub
' On new frame ready
Private Sub pCameraWindow_NewFrame(sender As Object, e As System.EventArgs)
Invalidate()
End Sub
End Class
End Namespace
Namespace Global.FrameGrabber
' ...
End Namespace
导入系统集合
导入System.ComponentModel
导入系统。绘图
导入系统数据
导入System.Windows.Forms
导入系统线程
名称空间帧捕获器
'''
“CameraWindow”的摘要说明。
'''
公共类CameraWindow
继承System.Windows.Forms.Control
专用m_摄像头作为摄像头=无
私有m_自动调整为布尔值=False
Private needSizeUpdate为布尔值=False
Private firstFrame作为布尔值=True
'自动调整属性大小
_
公共重写属性AutoSize()为布尔值
得到
返回m_自动调整大小
结束
设置(值为布尔值)
m_autosize=值
更新位置()
端集
端属性
“相机属性
_
公共属性摄影机()作为摄影机
得到
回程照相机
结束
设置(值为摄影机)
“锁
监视器。输入(Me)
'分离事件
如果你的相机不是什么都不是
RemoveHandler m_camera.NewFrame,地址Me.pCameraWindow_NewFrame
如果结束
m_摄影机=值
needSizeUpdate=True
第一帧=真
“阿塔赫事件
如果你的相机不是什么都不是
AddHandler m_camera.NewFrame,地址Me.pCameraWindow_NewFrame
如果结束
"解锁",
监视器。[退出](我)
端集
端属性
'构造器
公共分新()
初始化组件()
SetStyle(ControlStyles.AllPaintingInWmPaint或ControlStyles.DoubleBuffer或ControlStyles.ResizerDraw或ControlStyles.UserPaint,True)
端接头
#区域“Windows窗体设计器生成的代码”
私有子初始化组件()
Me.SuspendLayout()
Me.ResumeLayout(错误)
端接头
#末端区域
“油漆控制
受保护的覆盖子OnPaint(pe作为PaintEventArgs)
如果(需要大小更新)或(第一帧),则
更新位置()
needSizeUpdate=False
如果结束
“锁
监视器。输入(Me)
尺寸g为图形=pe.图形
将rc标注为矩形=Me.ClientRectangle
如果你的相机不是什么都不是
尝试
m_camera.Lock()
“画框
如果m_camera.LastFrame不是空的,那么
g、 DrawImage(m_camera.LastFrame,rc.X+1,rc.Y+1,rc.Width-2,rc.Height-2)
firstFrame=False
其他的
'创建字体和笔刷
暗淡的drawFont作为新字体(“Arial”,12)
与新SolidBrush一样暗淡的drawBrush(颜色:白色)
g、 DrawString(“连接…”,drawFont,drawBrush,新系统。绘图。点F(5,5))
drawBrush.Dispose()
drawFont.Dispose()
如果结束
捕获generatedExceptionName作为异常
最后
m_camera.Unlock()
结束尝试
如果结束
"解锁",
监视器。[退出](我)
MyBase.OnPaint(pe)
端接头
公共函数getImage()作为图像
如果不是的话,m_相机什么都不是
如果不是m_camera.LastFrame,则什么都不是
返回m_camera.LastFrame
如果结束
如果结束
一无所获
端函数
'更新控件的位置和大小
公共子更新位置()
“锁
监视器。输入(Me)
如果(m_autosize)和(Me.Parent不是空的),那么
将rc标注为矩形=Me.Parent.ClientRectangle
尺寸宽度为整数=320
变暗高度为整数=240
如果你的相机不是什么都不是
m_camera.Lock()
'获取框架维度
如果m_camera.LastFrame不是空的,那么
宽度=m_camera.LastFrame.width
高度=m_camera.LastFrame.height
如果结束
m_camera.Unlock()
如果结束
'
Me.SuspendLayout()
Me.Location=新点((rc.Width-Width-2)\2,(rc.Height-Height-2)\2)
Me.Size=新尺寸(宽度+2,高度+2)
我
如果结束
"解锁",
监视器。[退出](我)
端接头
“在新的框架上准备好了吗
私有子pCameraWindow_NewFrame(发送方作为对象,e作为System.EventArgs)
使无效
端接头
末级
结束命名空间
谢谢你的帮助 您需要更改项目的根命名空间或覆盖它。当您将类包装在命名空间
块(例如命名空间FrameGrabber
)中时,给定的命名空间相对于项目的根命名空间。换句话说,如果根命名空间是WindowsApplication1
,那么当您说namespace FrameGrabber
,所有包含的类型实际上都将位于WindowsApplication1.FrameGrabber
命名空间中
如果要覆盖一段代码的根名称空间,可以使用Global
关键字,这样名称空间声明就不是r