|
Dave Kreskowiak wrote: <stathread()> _
Shared Sub Main()
Using loginForm As New MyLoginForm
Application.Run(loginForm)
If loginForm.DialogResult = Windows.Forms.DialogResult.OK Then
If loginForm.LoginSuccessful Then
Application.Run(New MyMainForm)
End If
End If
End Using
End Sub
Thank you very much for your help, but can you please tell me where do i put this code. I'm student learning so i don't really know much about Visual Basic.
Thanks
Parth Patel
|
|
|
|
|
Either in a Module (yuk!) or in your startup form's code. Then you go into your project properties and change the Startup item to Sub Main .
|
|
|
|
|
hi there,
can someone help me on how will i pass or copy (programmatically) the information inside or declared on the datagridview1 to datagridview2.
It's like on text box.. textbox1.text = textbox2.text
i just want the datagridview2 to have the data inside the datagridview1(through a mouse click) but without the use of any dataset coz it's not binded with the sql database.
can you show me codes.
i really can't figure it out eh..
thank you so much..;)
|
|
|
|
|
without trying it:
datagridview2.datasource = datagridview1.datasource
datagridview2.datamember = datagridview1.datamember
datagridview2.refresh
???
|
|
|
|
|
this is just what i need..
I tried to use this codes and it works, with the use of some codes such as the declaration of the datatable columns.
thanks a lot..
this really helped me.
|
|
|
|
|
I have many forms in my application but I am not able to close last Form just after shited to the another Form(eg I'm in Form1 and click on button to go to another Form then the Form2 will open successfully but previous Form (Form1) also open in the background).
Pls suggest me what should I do?
regards
Praveen
|
|
|
|
|
There are many ways of doing it.
1. Form.Visible = Fale ' this will hide your form in any Visual Basic Version
2. Unload Form ' this is only for VB6. this will unload your form
3. Form.Close()
4. Form.Dispose()
No. 3 & 4 works with VB2005
And ye Use ME insted of form, because sometimes form might give u error.
Post back if u have anymore questions.
Parth Patel
|
|
|
|
|
Hi guys,
Just want to ask anyone who knows how to use a graph in vb.net? i haven't used a component ever since so i'm really new at this.
i have a component in vb.net called Microsoft Chart. i just don't know how to work on it.
if you can tell me a tutorial site, please do. I just badly need it.
or does anybody know any other components that i can use for charting?
i also need some sample codes to study on how to adjust the bargraph stats programmatically. Can you give me?
Hope you guys would help me.
Thank you.
|
|
|
|
|
Hey
You may want to look at simpler components first, is there no documentation on your chart component on www.msdn.com?
Maybe try some general VB tutorials first http://www.homeandlearn.co.uk/NET/vbNet.html - my apologies if these seem too simple but I dont know what standard you are at. Also try amazon for books on VB.NET - better to walk before you run.
Dan
|
|
|
|
|
ok, I'll take your advice.
Thank you so much..
|
|
|
|
|
|
I have an owner-owned pair of forms and I'd like to raise events from one to the other. I can't seem to find it in the big tome I use. Any ideas?
Richard H.
|
|
|
|
|
without better specefied what you have and what you want I can only tell you this:
declare a public event in the owned form
lets call it
public event bla
then when you need to catch the event (in the owner form)
say when a button is cliced on the owned form put
raisevent bla in the buttonclick event
then in the owner form you should be able to add a handler to the event bla
dim frm as ownedfrom
addhandler frm.bla, addressof blabla
private sub blabla (sender as object,e as system.eventargs)
'do you're code here
end sub
hope it helps
ps: sorry about the poor naming but it's been a long day (really need to get some sleep )
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistaks.
|
|
|
|
|
A better choice would be a delegate but here's how you'd do it...
Class Form1
private withevents moForm2 as Form2
Private sub Form1_Load(sender as object, e as system.eventargs) handles Form1.Load
moForm2 = New Form2
End Sub
private sub moForm2_Selection(sDate as String) handles moForm2.Selection
'do whatever you want
End Sub
End Class
Class Form2
Event Selection(sDate as String)
Private Sub Test()
RaiseEvent Selection("09/19/2007")
End Sub
End Class
|
|
|
|
|
You guys got me started, thanks. It was a custom event from an "owner" form to its "owned" form. I tried several ways, unsuccessfully. It wasn't until I declared the event as Shared in the owner form that everything fell into place nicely.
Thanks for your help.
Richard H.
|
|
|
|
|
Hi
I'm currently working on a program for automated print queue creation (move, copy, clone). Creating a print queue with AddPrinter on remote server works, but I can't figure out how to apply the DEVMODE. The code works as follows:
-using OpenPrinter to get the handle to the printer on the source server
-query printer with GetPrinter to get Printer_Info_2 and DEVMODE structure
-changing the needed values in the Printer_Info_2 and DEVMODE structure
-using AddPrinter to create the printer on the destination server
now I want to set the "Document Defaults" (like Collate or Orientation), but the API call DocumentProperties fails....
Public Function fMovePrinter( _<br />
<br />
ByVal sSource As String, _<br />
<br />
ByVal sDestination As String, _<br />
<br />
ByVal sPrinter As String, _<br />
<br />
ByVal lvSource As ListView, _<br />
<br />
ByVal lvDestination As ListView, _<br />
<br />
ByVal bDelete As Boolean _<br />
<br />
) As Boolean<br />
<br />
'first open the source printer to get the handle<br />
<br />
Dim hSource As IntPtr<br />
<br />
Dim pd As New PRINTER_DEFAULTS<br />
<br />
pd.DesiredAccess = PrinterAccessRights.PRINTER_ALL_ACCESS<br />
<br />
If Not OpenPrinter(sPrinter, hSource, pd) Then<br />
<br />
Throw New Exception(Err.LastDllError & " unable to OpenPrinter " & sPrinter)<br />
<br />
Return False<br />
<br />
End If<br />
<br />
'now call the GetPrinter API to get the PRINTER_INFO_2 structure<br />
<br />
Dim BytesWritten As Int32 = 0<br />
<br />
Dim ptBuf As IntPtr<br />
<br />
Dim pi2 As New PRINTER_INFO_2<br />
<br />
Dim dmOut As New DEVMODE<br />
<br />
ptBuf = Marshal.AllocHGlobal(1)<br />
<br />
'Get the number of bytes needed<br />
<br />
If Not GetPrinter(hSource, 2, ptBuf, 1, BytesWritten) Then<br />
<br />
If BytesWritten > 0 Then<br />
<br />
Marshal.FreeHGlobal(ptBuf)<br />
<br />
ptBuf = Marshal.AllocHGlobal(BytesWritten)<br />
<br />
'Get the PRINTER_INFO_2 structure<br />
<br />
If GetPrinter(hSource, 2, ptBuf, BytesWritten, BytesWritten) Then<br />
<br />
Marshal.PtrToStructure(ptBuf, pi2)<br />
<br />
If pi2.lpDeviceMode > 0 Then<br />
<br />
'Get the DEVMODE structure<br />
<br />
Dim ptrDevMode As New IntPtr(pi2.lpDeviceMode)<br />
<br />
Marshal.PtrToStructure(ptrDevMode, dmOut)<br />
<br />
End If<br />
<br />
Else<br />
<br />
Marshal.FreeHGlobal(ptBuf)<br />
<br />
ClosePrinter(hSource)<br />
<br />
Throw New Exception(Err.LastDllError & " unable to GetPrinter #2 " & sPrinter)<br />
<br />
Return False<br />
<br />
End If<br />
<br />
'free ptBuf<br />
<br />
Marshal.FreeHGlobal(ptBuf)<br />
<br />
ClosePrinter(hSource)<br />
<br />
Else<br />
<br />
Throw New Exception(Err.LastDllError & " BytesWritten " & BytesWritten)<br />
<br />
Return False<br />
<br />
End If<br />
<br />
Else<br />
<br />
Throw New Exception(Err.LastDllError & " unable to GetPrinter #1 " & sPrinter)<br />
<br />
Return False<br />
<br />
End If<br />
<br />
'modify the pi2 structure with the needed parameters<br />
<br />
Dim strPrinter As String<br />
<br />
strPrinter = sPrinter<br />
<br />
If strPrinter.LastIndexOf("\") > 0 Then<br />
<br />
strPrinter = strPrinter.Remove(strPrinter.IndexOf("\"), strPrinter.LastIndexOf("\") + 1)<br />
<br />
End If<br />
<br />
With pi2<br />
<br />
.pPrinterName = strPrinter<br />
<br />
.pServerName = sDestination<br />
<br />
.pPortName = "LPT1:"<br />
<br />
End With<br />
<br />
'change the DEVMODE structure with the needed parameters<br />
<br />
With dmOut<br />
<br />
.pDeviceName = "\\" & sDestination & "\" & strPrinter<br />
<br />
End With<br />
<br />
'copy the devmode structure back into the PRINTER_INFO_2 structure<br />
<br />
'Dim hdmIn As IntPtr<br />
<br />
pi2.lpDeviceMode = Marshal.AllocHGlobal(Marshal.SizeOf(dmOut))<br />
<br />
Marshal.StructureToPtr(dmOut, pi2.lpDeviceMode, False)<br />
<br />
<br />
<br />
'create the printer on the destination<br />
<br />
Dim hDestination As IntPtr<br />
<br />
hDestination = AddPrinter("\\" & sDestination, 2, pi2)<br />
<br />
If hDestination = 0 Then<br />
<br />
Throw New Exception(Err.LastDllError & " unable to AddPrinter")<br />
<br />
Return False<br />
<br />
End If<br />
<br />
Dim intRet As Int32<br />
<br />
intRet = DocumentProperties(IntPtr.Zero, hDestination, strPrinter, pi2.lpDeviceMode, pi2.lpDeviceMode, DocumentPropertiesModes.DM_IN_BUFFER Or DocumentPropertiesModes.DM_OUT_BUFFER)<br />
<br />
Debug.Print(Err.LastDllError)<br />
<br />
Return True<br />
<br />
<br />
<br />
<br />
<br />
End Function<br />
<br />
<br />
<br />
|
|
|
|
|
ok, I updated the code and now the DocumentProperties function returns no error... but the settings are not applied on the new printer....
Public Function fMovePrinter( _<br />
ByVal sSource As String, _<br />
ByVal sDestination As String, _<br />
ByVal sPrinter As String, _<br />
ByVal lvSource As ListView, _<br />
ByVal lvDestination As ListView, _<br />
ByVal bDelete As Boolean _<br />
) As Boolean<br />
<br />
'first open the source printer to get the handle<br />
Dim hSource As IntPtr<br />
Dim pd As New PRINTER_DEFAULTS<br />
<br />
pd.DesiredAccess = PrinterAccessRights.PRINTER_ALL_ACCESS<br />
If Not OpenPrinter(sPrinter, hSource, pd) Then<br />
Throw New Exception(Err.LastDllError & " unable to OpenPrinter " & sPrinter)<br />
Return False<br />
End If<br />
<br />
'now call the GetPrinter API to get the PRINTER_INFO_2 structure<br />
Dim BytesWritten As Int32 = 0<br />
Dim ptBuf As IntPtr<br />
Dim pi2 As New PRINTER_INFO_2<br />
Dim dmOut As New DEVMODE<br />
<br />
ptBuf = Marshal.AllocHGlobal(1)<br />
<br />
'Get the number of bytes needed<br />
If Not GetPrinter(hSource, 2, ptBuf, 1, BytesWritten) Then<br />
If BytesWritten > 0 Then<br />
Marshal.FreeHGlobal(ptBuf)<br />
ptBuf = Marshal.AllocHGlobal(BytesWritten)<br />
'Get the PRINTER_INFO_2 structure<br />
If GetPrinter(hSource, 2, ptBuf, BytesWritten, BytesWritten) Then<br />
Marshal.PtrToStructure(ptBuf, pi2)<br />
If pi2.lpDeviceMode > 0 Then<br />
'Get the DEVMODE structure<br />
Dim ptrDevMode As New IntPtr(pi2.lpDeviceMode)<br />
Marshal.PtrToStructure(ptrDevMode, dmOut)<br />
End If<br />
Else<br />
Marshal.FreeHGlobal(ptBuf)<br />
ClosePrinter(hSource)<br />
Throw New Exception(Err.LastDllError & " unable to GetPrinter #2 " & sPrinter)<br />
Return False<br />
End If<br />
'free ptBuf<br />
Marshal.FreeHGlobal(ptBuf)<br />
'ClosePrinter(hSource)<br />
Else<br />
Throw New Exception(Err.LastDllError & " BytesWritten #1 " & BytesWritten)<br />
Return False<br />
End If<br />
<br />
Else<br />
Throw New Exception(Err.LastDllError & " unable to GetPrinter #1 " & sPrinter)<br />
Return False<br />
End If<br />
<br />
'modify the pi2 structure with the needed parameters<br />
Dim strPrinter As String<br />
strPrinter = sPrinter<br />
If strPrinter.LastIndexOf("\") > 0 Then<br />
strPrinter = strPrinter.Remove(strPrinter.IndexOf("\"), strPrinter.LastIndexOf("\") + 1)<br />
End If<br />
<br />
With pi2<br />
.pPrinterName = strPrinter<br />
.pServerName = sDestination<br />
.pPortName = "LPT1:"<br />
End With<br />
<br />
'change the DEVMODE structure with the needed parameters<br />
Dim strFullPrinterPath As String = "\\" & sDestination & "\" & strPrinter<br />
With dmOut<br />
.pDeviceName = strFullPrinterPath<br />
End With<br />
<br />
'copy the devmode structure back into the PRINTER_INFO_2 structure<br />
'Dim hdmIn As IntPtr<br />
pi2.lpDeviceMode = Marshal.AllocHGlobal(Marshal.SizeOf(dmOut))<br />
Marshal.StructureToPtr(dmOut, pi2.lpDeviceMode, False)<br />
<br />
If bDelete = True Then<br />
Call DeletePrinter(hSource)<br />
hSource = IntPtr.Zero<br />
End If<br />
<br />
'create the printer on the destination<br />
Dim hDestination As IntPtr<br />
hDestination = AddPrinter("\\" & sDestination, 2, pi2)<br />
If hDestination = 0 Then<br />
If Err.LastDllError = 1802 Then<br />
Call DeletePrinter(hSource)<br />
Debug.Print(Err.LastDllError.ToString)<br />
hDestination = AddPrinter("\\" & sDestination, 2, pi2)<br />
If hDestination = 0 Then<br />
Throw New Exception(Err.LastDllError & " unable to AddPrinter, tried twice because printer allready exists on " & sDestination)<br />
Return False<br />
End If<br />
Else<br />
Throw New Exception(Err.LastDllError & " unable to AddPrinter")<br />
Return False<br />
End If<br />
End If<br />
<br />
If hSource <> 0 Then<br />
ClosePrinter(hSource)<br />
hSource = IntPtr.Zero<br />
End If<br />
<br />
'dmOut = Nothing<br />
<br />
Dim intRet As Int32<br />
'get size of the DEVMODE structure<br />
intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, IntPtr.Zero, IntPtr.Zero, DocumentPropertiesModes.DM_GETSIZE)<br />
If intRet < 0 Then<br />
Throw New Exception(Err.LastDllError & " unable to get DocumentProperties #1")<br />
Return False<br />
End If<br />
<br />
'create a new instance of the DEVMODE structure with size returned<br />
Dim hdmIn As IntPtr<br />
hdmIn = Marshal.AllocHGlobal(intRet)<br />
<br />
intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, hdmIn, IntPtr.Zero, DocumentPropertiesModes.DM_OUT_BUFFER)<br />
If intRet < 0 Then<br />
Throw New Exception(Err.LastDllError & " unable to get DocumentProperties #2")<br />
Return False<br />
End If<br />
<br />
'get the structure from the pointer<br />
Dim dmIn As New DEVMODE<br />
dmIn = Marshal.PtrToStructure(hdmIn, dmIn.GetType)<br />
<br />
'modify the structure with the settings from the source printer<br />
With dmIn<br />
.dmCollate = dmOut.dmCollate<br />
.dmColor = dmOut.dmColor<br />
.dmCopies = dmOut.dmCopies<br />
.dmDefaultSource = dmOut.dmDefaultSource<br />
.dmDuplex = dmOut.dmDuplex<br />
.dmFormName = dmOut.dmFormName<br />
.dmMediaType = dmOut.dmMediaType<br />
.dmOrientation = dmOut.dmOrientation<br />
.dmPaperLength = dmOut.dmPaperLength<br />
.dmPaperSize = dmOut.dmPaperSize<br />
.dmPaperWidth = dmOut.dmPaperWidth<br />
.dmPrintQuality = dmOut.dmPrintQuality<br />
.dmScale = dmOut.dmScale<br />
.dmSize = dmOut.dmSize<br />
.dmTTOption = dmOut.dmTTOption<br />
End With<br />
<br />
'copy the structure back in the pointer<br />
Marshal.StructureToPtr(dmIn, hdmIn, False)<br />
<br />
'set the new settings on the destination printer<br />
intRet = DocumentProperties(IntPtr.Zero, hDestination, strFullPrinterPath, hdmIn, hdmIn, DocumentPropertiesModes.DM_IN_BUFFER Or DocumentPropertiesModes.DM_OUT_BUFFER)<br />
If intRet < 0 Then<br />
Throw New Exception(Err.LastDllError & " unable to set DocumentProperties #1")<br />
Return False<br />
End If<br />
<br />
'reget the PRINTER_INFO_2 structure from the destination printer<br />
Dim PI2In As New PRINTER_INFO_2<br />
'Dim hPI2In As IntPtr<br />
BytesWritten = 0<br />
ptBuf = Marshal.AllocHGlobal(1)<br />
If Not GetPrinter(hDestination, 2, ptBuf, 1, BytesWritten) Then<br />
If BytesWritten > 0 Then<br />
Marshal.FreeHGlobal(ptBuf)<br />
ptBuf = Marshal.AllocHGlobal(BytesWritten)<br />
'reget the PRINTER_INFO_2 structure<br />
If GetPrinter(hDestination, 2, ptBuf, BytesWritten, BytesWritten) Then<br />
Marshal.PtrToStructure(ptBuf, PI2In)<br />
PI2In.lpDeviceMode = hdmIn<br />
'hPI2In = Marshal.AllocHGlobal(Marshal.SizeOf(PI2In))<br />
'Marshal.StructureToPtr(PI2In, hPI2In, False)<br />
intRet = SetPrinter(hDestination, 2, PI2In, PrinterControlCommands.PRINTER_CONTROL_SETPRINTERINFO)<br />
Debug.Print(Err.LastDllError)<br />
If intRet = 0 Then<br />
Throw New Exception(Err.LastDllError & " unable to SetPrinter #1")<br />
Return False<br />
End If<br />
Else<br />
Marshal.FreeHGlobal(ptBuf)<br />
ClosePrinter(hDestination)<br />
Throw New Exception(Err.LastDllError & " unable to GetPrinter #3 " & strFullPrinterPath)<br />
Return False<br />
End If<br />
Else<br />
Throw New Exception(Err.LastDllError & " BytesWritten #2 " & BytesWritten)<br />
Return False<br />
End If<br />
End If<br />
Call ClosePrinter(hDestination)<br />
Marshal.FreeHGlobal(hdmIn)<br />
Dim lvItem As New ListViewItem<br />
lvItem = lvDestination.Items.Add(sPrinter)<br />
lvItem.SubItems.Add(PI2In.pDriverName)<br />
lvItem.SubItems.Add(PI2In.pShareName)<br />
lvDestination.Refresh()<br />
Me.Refresh()<br />
pi2 = Nothing<br />
PI2In = Nothing<br />
dmIn = Nothing<br />
dmOut = Nothing<br />
Return True<br />
End Function
|
|
|
|
|
can someone help me..
how can you make a report using crystal report and the source is from the datagridview.. i need to have a printable copy of the data in the datagridview..
pls help...
gt
|
|
|
|
|
can pls someone help me how to save all items in a listview to the database....
pls help...
gt
|
|
|
|
|
Pretty vague question you can reply being more specific. The vague answer is to iterate through the items in the listview, and insert them into your DB item by item
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I want retive system of time.how to get it?
thank you
|
|
|
|
|
I googled "vb.net get time"
Here is the what I found on the third line:
<br />
Dim Now AsDateTime = DateTime.Now<br />
MessageBox.Show(Now)<br />
You always pass failure on the way to success.
|
|
|
|
|
|
Hm... I don't want to appear impolite but how about googling it?
Oh - and you're welcome
You always pass failure on the way to success.
|
|
|
|
|
|