Windows Forms
리소스Windows Forms FAQ
Windows Forms FAQ에서는 Windows Forms 응용 프로그램, 컨트롤 작성 및 사용, 도구, 일반적인 .NET 질문 사항 등을 다루며 Whidbey 베타 릴리스의 초기 Windows Forms 2.0 기술에 대해서도 설명합니다. | 커뮤니티 및 지원
Microsoft 플랫폼에서 Windows Forms 스마트 클라이언트를 사용 및 작성하는 방법에 대한 추가 도움말과 정보를 확인하십시오. | 온라인 토론
스마트 클라이언트를 중심으로 하는 온라인 토론 그룹에 참여하여 질문을 하거나 정보를 공유하거나 다른 사람들과 의견을 나누십시오. | 도구 및 코드 샘플
이 페이지에서는 Microsoft 기술을 사용하여 스마트 클라이언트 응용 프로그램을 작성하기 위한 도구와 코드 샘플을 제공합니다. | 서적
스마트 클라이언트 응용 프로그램 개발과 관련된 다양한 주제를 이해하는 데 도움이 되는 수많은 책들 중에서 몇 개를 읽어보십시오. | 컬럼
MSDN의 최고 작가들이 정기적으로 제공하는 스마트 클라이언트 기술과 관련된 컬럼을 읽어보십시오. | 사례 연구
Microsoft의 고객들이 스마트 클라이언트 응용 프로그램을 사용하여 무엇을 하고 있으며 실제 현장에서 스마트 클라이언트 기술이 어떻게 사용되고 있는지 알 수 있는 사례 연구를 확인하십시오. | 컨트롤 갤러리 (영문)
컨트롤 갤러리는 응용 프로그램에서 사용할 수 있는 300개 이상의 Windows Forms 컨트롤이 포함된 디렉터리입니다. 컨트롤의 범주에는 사용자 지정 폼, 데이터, 동적 UI 작성, 그래픽, HTML 상호 작용, 목록 컨트롤, 인쇄 및 보고, 텍스트, 도구 모음, 단추 및 메뉴, Windows XP, 마법사 등이 있습니다. 또한 컨트롤 갤러리에는 컨트롤 개발 웹 포럼이 포함되어 있습니다. 이 포럼을 사용하면 나열된 컨트롤을 사용하는 방법에 대한 도움과 함께 고유한 컨트롤을 작성하는 방법에 대한 조언을 얻을 수 있습니다. |
| | 최신 Windows Forms 포럼.gif)
Marquee progress bar not working in VS 2005Howdy all, In VS 2005 I put a progress bar on a form. I set the style to Marquee, but can't figure out how to make it run. The progress bar is always blank. I want it to just scroll continuously because the time it takes for the background operation cannot be determined. I'm running Windows XP Pro w/ SP2 and .NET 2.0 (I already read the thread about the Marquee style not working in Windows 2000, that's not the problem here). I have tried calling ProgressBar.PerformStep() and ProgressBar.Increment(). Both times, an exception was thrown stating that the method should not be called with a style of Marquee. So....Does anybody know what I'm doing wrong? The outline of the progress bar is there and I can see it in the designer; I just can't get it to show anything. Thanks, Dan
requested operation cant be performed on file with user-mapped section openhiya, I get the above error in my winforms app. The complete error is:
The file 'uipMyApp.Launcher.exe' cannot be copied to the run directory. The requested operation cannot be performed on a file with a user-mapped section open. <\error>
I have googled + errorBank but am none the wiser.Has anyone had this error before?
cheers, yogi
Interacting with other windows/apps?I know this is possible, just wondering if it's possible in C#.NET, and how it's done.
I'd like my application to interact with other apps/windows. Examples:
1) Type some text into a notepad window. 2) Force Firefox to do Help->About. 3) Read text from a notepad window.
I realize #3 could potentially be a security risk and .NET may not allow it (imagine an app reading text from some open window and sending it off somewhere via the net).
And in case anyone is concerned, no, I'm not trying to write any kind of malware or virus. I'm interested in writing a program that will automate tedious processes in another application. I guess this is similar to Rexx.
So, how can I do something like this?
How to: Webbrowser NewWindow and Navigating equivalent to axWebbrowserAt first, I enjoyed the new webbrowser control but then I noticed that the args provided by the events NewWindow3 and BeforeNavigate of the axWebBrowser had not been implemented in the new control. Arg.
Good news, the guys from Microsoft gave us the a workaround recently in C# and said they will publish a sample soon on MSDN.
In the mean time, here is some VB.net code inspired from Microsoft's C# that will give you 2 new events and the args people like me were crying for.
NavigatingExtended gives you the following args: - Url as string - Frame as string - Headers as string - Postdata as string - PostdataByte() as byte - Cancel as boolean (to cancel navigation)
NewWindowExtended gives you the following args: - Url as string - UrlContext as string - Flags as NWMF (see NewWindow3 on MSDN for definition) - Cancel as boolean (to cancel navigation to new window)
Ok let's go. 1. Create a new Windows form project. 2. Add a new Module and Copy/Paste the following:
| |
Imports System Imports System.Collections.Generic Imports System.Text Imports System.ComponentModel Imports System.Runtime.InteropServices
Module Module1
Public Enum NWMF NWMF_UNLOADING = &H1& NWMF_USERINITED = &H2& NWMF_FIRST_USERINITED = &H4& NWMF_OVERRIDEKEY = &H8& NWMF_SHOWHELP = &H10& NWMF_HTMLDIALOG = &H20& NWMF_FROMPROXY = &H40& End Enum
'First define a new EventArgs class to contain the newly exposed data Public Class WebBrowserNavigatingExtendedEventArgs Inherits CancelEventArgs
Private m_Url As String Private m_Frame As String Private m_Postdata() As Byte Private m_Headers As String
Public ReadOnly Property Url() As String Get Return m_Url End Get End Property
Public ReadOnly Property Frame() As String Get Return m_Frame End Get End Property
Public ReadOnly Property Headers() As String Get Return m_Headers End Get End Property
Public ReadOnly Property Postdata() As String Get Return PostdataToString(m_Postdata) End Get End Property
Public ReadOnly Property PostdataByte() As Byte() Get Return m_Postdata End Get End Property
Public Sub New(ByVal url As String, ByVal frame As String, ByVal postdata As Byte(), ByVal headers As String) m_Url = url m_Frame = frame m_Postdata = postdata m_Headers = headers End Sub
Private Function PostdataToString(ByVal p() As Byte) As String 'not sexy but it works... Dim tabpd() As Byte, bstop As Boolean = False, stmp As String = "", i As Integer = 0 tabpd = p If tabpd Is Nothing OrElse tabpd.Length = 0 Then Return "" Else For i = 0 To tabpd.Length - 1 stmp += ChrW(tabpd(i)) Next stmp = Replace(stmp, ChrW(13), "") stmp = Replace(stmp, ChrW(10), "") stmp = Replace(stmp, ChrW(0), "") End If If stmp = Nothing Then Return "" Else Return stmp End If End Function
End Class
Public Class WebBrowserNewWindowExtendedEventArgs Inherits CancelEventArgs
Private m_Url As String Private m_UrlContext As String Private m_Flags As NWMF
Public ReadOnly Property Url() As String Get Return m_Url End Get End Property
Public ReadOnly Property UrlContext() As String Get Return m_UrlContext End Get End Property
Public ReadOnly Property Flags() As NWMF Get Return m_Flags End Get End Property
Public Sub New(ByVal url As String, ByVal urlcontext As String, ByVal flags As NWMF) m_Url = url m_UrlContext = urlcontext m_Flags = flags End Sub
End Class
Public Class ExtendedWebBrowser Inherits WebBrowser
Private cookie As AxHost.ConnectionPointCookie Private wevents As WebBrowserExtendedEvents
'This method will be called to give you a chance to create your own event sink Protected Overrides Sub CreateSink() 'MAKE SURE TO CALL THE BASE or the normal events won't fire MyBase.CreateSink() wevents = New WebBrowserExtendedEvents(Me) cookie = New AxHost.ConnectionPointCookie(Me.ActiveXInstance, wevents, GetType(DWebBrowserEvents2)) End Sub
Protected Overrides Sub DetachSink() If Not cookie Is Nothing Then cookie.Disconnect() cookie = Nothing End If MyBase.DetachSink() End Sub
'This new event will fire when the page is navigating Public Delegate Sub WebBrowserNavigatingExtendedEventHandler(ByVal sender As Object, ByVal e As WebBrowserNavigatingExtendedEventArgs) Public Event NavigatingExtended As WebBrowserNavigatingExtendedEventHandler
'This event will fire when a new window is about to be opened Public Delegate Sub WebBrowserNewWindowExtendedEventHandler(ByVal sender As Object, ByVal e As WebBrowserNewWindowExtendedEventArgs) Public Event NewWindowExtended As WebBrowserNewWindowExtendedEventHandler
Protected Friend Sub OnNavigatingExtended(ByVal Url As String, ByVal Frame As String, ByVal Postdata As Byte(), ByVal Headers As String, ByRef Cancel As Boolean) Dim e As WebBrowserNavigatingExtendedEventArgs = New WebBrowserNavigatingExtendedEventArgs(Url, Frame, Postdata, Headers) RaiseEvent NavigatingExtended(Me, e) Cancel = e.Cancel End Sub
Protected Friend Sub OnNewWindowExtended(ByVal Url As String, ByRef Cancel As Boolean, ByVal Flags As NWMF, ByVal UrlContext As String) Dim e As WebBrowserNewWindowExtendedEventArgs = New WebBrowserNewWindowExtendedEventArgs(Url, UrlContext, Flags) RaiseEvent NewWindowExtended(Me, e) Cancel = e.Cancel End Sub
End Class
'This class will capture events from the WebBrowser Class WebBrowserExtendedEvents Inherits System.Runtime.InteropServices.StandardOleMarshalObject Implements DWebBrowserEvents2
Private m_Browser As ExtendedWebBrowser
Public Sub New(ByVal browser As ExtendedWebBrowser) m_Browser = browser End Sub
'Implement whichever events you wish Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As String, ByRef flags As Object, ByRef targetFrameName As String, ByRef postData As Object, ByRef headers As String, ByRef cancel As Boolean) Implements DWebBrowserEvents2.BeforeNavigate2
m_Browser.OnNavigatingExtended(URL, targetFrameName, CType(postData, Byte()), headers, cancel)
End Sub
Public Sub NewWindow3(ByVal pDisp As Object, ByRef Cancel As Boolean, ByRef Flags As Object, ByRef UrlContext As String, ByRef Url As String) Implements DWebBrowserEvents2.NewWindow3
m_Browser.OnNewWindowExtended(Url, Cancel, CType(Flags, NWMF), UrlContext)
End Sub
End Class
Guid("34A715A0-6587-11D0-924A-0020AFC7AC4D"), _ InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch), _ TypeLibType(TypeLibTypeFlags.FHidden)> _ Public Interface DWebBrowserEvents2
_ Sub BeforeNavigate2(<[In](), MarshalAs(UnmanagedType.IDispatch)> ByVal pDisp As Object, _ ByRef URL As String, _ ByRef flags As Object, _ ByRef targetFrameName As String, _ ByRef postdata As Object, _ ByRef headers As String, _ ByRef cancel As Boolean)
'Note: Postdata is a SafeArray but for some reason, if I do a proper declaration, the event will not be raised: '<[In](), MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_UI1)> ByRef postdata() As Byte, _
_ Sub NewWindow3( ByVal pDisp As Object, _ ByRef cancel As Boolean, _ ByRef Flags As Object, _ ByRef UrlContext As String, _ ByRef Url As String)
End Interface
End Module
|
3. Now, Open your form1 in Code view 4. Copy/Paste the following to test your control
| |
Public Class Form1 'Source from wilfridB
Private wb As New ExtendedWebBrowser
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandler wb.NavigatingExtended, AddressOf wb_NavigatingExtended AddHandler wb.DocumentCompleted, AddressOf wb_DocumentCompleted AddHandler wb.NewWindowExtended, AddressOf wb_NewWindowExtended Me.Controls.Add(wb) wb.Dock = DockStyle.Fill wb.Navigate(New Uri("http://www.microsoft.com"))
End Sub
Private Sub wb_NavigatingExtended(ByVal sender As Object, ByVal e As module1.WebBrowserNavigatingExtendedEventArgs) 'This is a new event
Dim postdata As String = e.Postdata Dim msg As String = "Navigating to : " & e.Url & ControlChars.CrLf msg &= "Postdata : " & postdata & ControlChars.CrLf msg &= "Headers : " & e.Headers & ControlChars.CrLf msg &= "Frame : " & e.Frame & ControlChars.CrLf msg &= "Continue ?" Dim res As DialogResult = MessageBox.Show(msg, "NavigatingExtended", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If res = Windows.Forms.DialogResult.No Then e.Cancel = True
End Sub
Private Sub wb_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) 'This is a standard event
MessageBox.Show("Document complete: " & e.Url.ToString, "DocumentCompleted", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub wb_NewWindowExtended(ByVal sender As Object, ByVal e As Module1.WebBrowserNewWindowExtendedEventArgs) 'This is a new event
Dim msg As String = "Navigation vers : " & e.Url & ControlChars.CrLf msg &= "UrlContext : " & e.UrlContext & ControlChars.CrLf msg &= "Flags : " & e.Flags.ToString & ControlChars.CrLf msg &= "Continue ?" Dim res As DialogResult = MessageBox.Show(msg, "NewWindowExtended", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If res = Windows.Forms.DialogResult.No Then e.Cancel = True
End Sub
End Class
|
That's it and it should work... Any comment or additional event implementation is welcome... And if somebody could give me the solution for properly retrieving the postdata using something like: <[In](), MarshalAs(UnmanagedType.SafeArray, safearraysubtype:=VarEnum.VT_UI1)> ByRef postdata() As Byte, _ And converting an array of byte in a more decent way, that would be great. wilfridB
How to check string is number or not in C#Hi! Enveryone:
I am new in C#. I want to check whether the user input to a text box is a number or not. What is the string function to check it? I do not want to use try and catch.
Thank you very much!
CLC
|
| |