|
Don't know about VB, but that won't work in C#.
|
|
|
|
|
CleaKO wrote: is this just simply a preference thing?
Both are correct and do the same. It is a preference thing.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
It's just a matter of preference. They both work the same, though, the nesting gives you a little more readability if you're using multiple objects and need them at different levels.
|
|
|
|
|
CleaKO wrote: Is one more correct than the other
there is no such thing as "more correct"; a statement is correct or it is not correct.
|
|
|
|
|
Technically in the example, does Object have a dispose method?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
kissdznuts wrote: does Object have a dispose method?
No, System.Object does not have a Dispose() method, so it does not implement IDisposable.
In C# you could make your own Object class, distinct from System.Object; however in VB.NET that seems not possible.
|
|
|
|
|
How to Disable the Close button or Remove the Close in Windows Forms!!!
Can anyone suggest me or Help me?
Regards...
Selva Shankar
|
|
|
|
|
If you mean the "X" in the right corner you can just set the form property "ControlBox" = False.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
|
|
|
|
|
HI Cleako,
Thanks for answering....
Your suggestion removes all the three buttons.But i need like Minimize button should be enabled,Maximize and Close buttons in Disable state.
Is there any suggestion or code with you?
Regards...
Selva Shankar
|
|
|
|
|
For disabling, you will need to paint the form yourself.
Cleako's reply would remove all the buttons in the control box.
Loading signature. Please wait...
|
|
|
|
|
Hi d@nish,
You are absolutely right for the cleako's answer.
Is there any other way except painting a new form?? B'coz, all my works in the application are over except this. if i paint a new form then i need to start from beginning.
Regards...
Selva Shankar
|
|
|
|
|
This is handled in User32.dll . I think there is GetSystemMenu function(Not sure about the name). Try dig in to it. You might find something useful.
[Edit]I hadn't gone through the code in post below. But that exactly what I was thinking.[/Edit]
Loading signature. Please wait...
|
|
|
|
|
You do not want the close the form at all? Then you could just cancel the close in the event fired when the X is clicked.
If you need to close the form using some other interface - a button for example, use a tag to show the path for the close event, and handle accordingly.
HTH
|
|
|
|
|
Maybe this will help. The original code came from this site
Jan
Option Explicit On
Public Class Form1
Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Const MF_STRING = &H0
Private Const MF_BYCOMMAND = &H0
Private Const WM_SYSCOMMAND = &H112
Private Const MF_BYPOSITION = &H400&
Public Const MF_SEPARATOR = &H800&
''' <summary>
''' Wis een commando via 0-based volgnummer in het systeem menu
''' </summary>
''' <param name="frm">De form van het systeem menu</param>
''' <param name="iPosition">De postitie 0-aantal -1</param>
''' <remarks></remarks>
Private Sub RemoveControlMenuItemByPosition(ByVal frm As Form, ByVal iPosition As Integer)
Dim iHSysMenu As Integer
Dim iReturn As Integer
Dim lDW As Long
Dim lRR As Long
iHSysMenu = GetSystemMenu(frm.Handle, 0)
iReturn = RemoveMenu(iHSysMenu, iPosition, MF_BYPOSITION)
lDW = GetWindowLong(frm.Handle, -16) 'Window style
lDW = lDW And &HFFFEFFFF 'Turn off bits for Maximize arrow button
lRR = SetWindowLong(frm.Handle, -16, lDW)
End Sub
Private Sub RemoveControlMenuItemByCommand(ByVal frm As Form, ByVal lCommand As _
Long)
Dim iHSysMenu As Long
Dim iReturn As Long
Dim lDW As Long
Dim lRR As Long
iHSysMenu = GetSystemMenu(frm.Handle, 0)
iReturn = RemoveMenu(iHSysMenu, lCommand, MF_BYCOMMAND)
lDW = GetWindowLong(frm.Handle, -16) 'Window style
lDW = lDW And &HFFFEFFFF 'Turn off bits for Maximize arrow button
lRR = SetWindowLong(frm.Handle, -16, lDW)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m) 'moet altijd hier staan
Const WM_HOTKEY As Integer = &H312
Const WM_COMMAND As Integer = &H112
Select Case m.Msg
Case WM_HOTKEY
Case WM_COMMAND
Select Case m.WParam
Case 2
MsgBox("You clicked to About")
Case 3
MsgBox("You clicked on Help")
Case 4
'This option removes the custom added menu items and the separator.
Dim iHSysMenu As Integer
' Dim iReturn As Integer
iHSysMenu = GetSystemMenu(Me.Handle, 0)
Call RemoveControlMenuItemByCommand(Me, 1) 'nrs moeten overeenkomen met aanmaak
Call RemoveControlMenuItemByCommand(Me, 2)
Call RemoveControlMenuItemByCommand(Me, 3)
Call RemoveControlMenuItemByCommand(Me, 4)
Call RemoveControlMenuItemByCommand(Me, 5)
Case 5
Call RemoveControlMenuItemByPosition(Me, 0)
Case 61587 'systeemmenu
Case 61458 'titelbalk
Case 61472 'minimaliseer
Case 61728 'restore
Case 61488 'maximaliseer
Case 61490 'dubbelclick titelbalk
Case 61456 'verplaatsen
Case 61440 'size menu
Case 61441 'size left
Case 61442 'size right
Case 61443 'size up
Case 61444 'size left up
Case 61445 'size right up
Case 61446 'size down
Case 61447 'size Left down
Case 61448 'size right down
Case Else
MsgBox("You clicked item " & m.WParam.ToString)
End Select
End Select
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iReturn As Long
Dim iHSysMenu As Long
iHSysMenu = GetSystemMenu(Me.Handle, 0)
'nrs moeten overeenkomen met wndproc
iReturn = AppendMenu(iHSysMenu, MF_SEPARATOR, 1, vbNullString)
iReturn = AppendMenu(iHSysMenu, MF_STRING, 2, "About...")
iReturn = AppendMenu(iHSysMenu, MF_STRING, 3, "Help...")
iReturn = AppendMenu(iHSysMenu, MF_STRING, 4, "Remove new items")
iReturn = AppendMenu(iHSysMenu, MF_STRING, 5, "Remove 1st item")
End Sub
End Class
|
|
|
|
|
how to search a particularfile from a folder.
I having a MS acces table containing two fields, files name and modification time. Want to read file name by name from table and want to check that file to be present in the folder and to compare that files modified time and time in table to be equal or not.
How to do these
denny
|
|
|
|
|
hi
add a reference to the Microsoft Scripting Runtime library:
C:\WINDOWS\system32\scrrun.dll
regards
|
|
|
|
|
Check out FILEINFO as it will give you what you need.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi all,
i am using master page in my project..
i am getting design issue...
it's working properly for IE, when it come to Fire fox,it not showing properly.how to fix it.
please help me..
Thanks in advance.....
JohnDas
|
|
|
|
|
Firstly, you need to provide more details of your problem, I'm guessing that it is a layout problem but you have to confirm this. Also, you will be better off posting on the correct board, the ASP.NET board (or maybe Web Development if it's a CSS issue). You're more likey to get an answer there.
|
|
|
|
|
Hi
When u look a page in IE and Firefox there is some small changes is there it is difficult correct. If it is huge change is there may be following problem are there.
1. CSS.
2. Browser Supportive.
3. alignment.
4. XML or backend coding
Etc....
|
|
|
|
|
In C# I have a form which creates an object of my class DirtyMarker for which I pass (among others) a reference to my closeControl.
In the DirtyMarker class I have this code:
pCloseCtrl.Click += new EventHandler((pObj, pArgs) =>
{
if (this.formIsDirty)
{
MessageBox.Show("There are unsaved changes, please save the changes before closing.");
}
else
{
pForm.Close();
}
});
How would I do this in VB?
My concern is not with the anonymous function, but rather with adding the "new" event.
Regards!
|
|
|
|
|
Adding an event is done by using the 'Addhandler'
Addhandler pCloseCtrl.click, addressof EventHandler(pObj,pArgs)
private sub EventHandler(pobj as object,pargs as eventargs)
'do your code here
end sub
evilnoodle wrote: anonymous function,
don't really know how to do this in vb
But when converting the code using:
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
I get:
AddHandler pCloseCtrl.Click, AddressOf Function(pObj, pArgs) Do
If Me.formIsDirty Then
MessageBox.Show("There are unsaved changes, please save the changes before closing.")
Else
pForm.Close()
End If
End Function
Never done it like that tho so don't really know if it works like you want it.
Hope this helps
|
|
|
|
|
Thanks but...
Your second solution is a far miss, VS wont accept that syntax.
The first solution is closer but when I do the EventHandler(pObj, pArgs) I get a compile time error stating that: 'AddressOf' operand must be the name of a method (without parentheses)
When I remove the parenthesis, it works but I get a NullReferenceException on that same line at runtime.
Any ideas?
|
|
|
|
|
evilnoodle wrote: Your second solution is a far miss, VS wont accept that syntax.
Could be didn't really test it its just the code you pasted run thru the converter. (did think it kinda looked strange)
evilnoodle wrote: The first solution is closer but when I do the EventHandler(pObj, pArgs) I get a compile time error stating that: 'AddressOf' operand must be the name of a method (without parentheses)
When I remove the parenthesis, it works but I get a NullReferenceException on that same line at runtime.
Your function (eventhandler) has to take the same parameters as the event it is delcared for (usually it "sender as object, e as eventargs")
so the code becomes
AddHandler frm.Click, AddressOf EventHandler
Private Sub EventHandler(ByVal pobj As Object, ByVal pargs As EventArgs)
'do your code here
MessageBox.Show("test")
End Sub
This works on my end. Can you post your code so I can see what might be wrong.
|
|
|
|
|
Here is what I have so far, I get a NullReferenceException on the AddHandler line.
This is not the same code as the DirtyMarker, but it comes down to the same implementation. This code is supposed to do something when the main form's Datagridview fires userDeletingRow.
Also please ignore the fact that this is a generic type class, I'll focus on that when I get these events to work.
Public Class DataFormLogic(Of T)
Public Sub New(ByRef DGV As DataGridView)
AddHandler DGV.UserDeletingRow, AddressOf MyDelete
'Also tried this, which give a delegate signature error at compile time
'AddHandler DGV.UserDeletingRow, New EventHandler(AddressOf MyDelete)
End Sub
Private Sub MyDelete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs)
MsgBox("Eureka!!!!!")
End Sub
End Class
-----------------------------------
UPDATE:
I just got it to work with a button on that same form, it must have something to do with the DataGridView... oh how I loathe that control! Could you try to get it going with a datagridview?
modified on Friday, December 5, 2008 3:32 AM
|
|
|
|
|