|
Ok, this is a little too much for me. I'm just a newbie programmer.
frmMain is my parent MDI form created in design time, it's not a self created class or anything. I know it's a class, just not one I created.
I didn't get to creating dll's yet. It's all self-study, and not much time.
It's got to be something with the way I use frmNewMain or something, I just don't see it. A little more help please?
If I use MessageBox.Show(frmNewMain.Text) it does show the caption text of the form, so that works.
|
|
|
|
|
Like too many people, you've jumped in at the deep end and you're trying to do windows forms programming, when you should be writing console code and learning how object orientation works.
A class is like an object factory. If I create a 'person' class, the idea is to wrap the concept of a person. So, a lot of the time, this means I want more than one 'person' in my code, and I want to wrap that concept, and once I do that, each person is unique. If I have bill and fred in my program, and I rename fred to tom, bill is still bill. In the same way, when you create a new instance of frmMain, you're creating a whole new form. It has nothing to do with the instance of frmMain that called this code, they are two seperate objects. What you're doing is the same as having a house that you want painted, so you buy a new house, and paint that. The old house has nothing to do with what you do the new one.
I assumed this code was in a dll, as you said it was for reuse. If you're a real beginner, I probably shot a whole lot of concepts at you ( like resources ) which made my reply confusing. The core answer is, you need to read about OO. Then, you'll see why this couldn't work. Put this functionality in new class, derived from the base Form class, and derive your form from that. That's how to reuse this code. It could also then go in a dll, quite easily, if you want that in future.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Does this mean I have to create a hole new form, in a seperate class, and use that as my main MDI form?
Back to chapter 5 it is then
Translating from English to Dutch doesn't make it any easier either
--edit--
Turned it in to a function
Public Function ConnStatusIcon(ByVal ConnState As String)<br />
<br />
<br />
Dim RedIcon As New Icon(Application.StartupPath & "\Icons\RedLight.ico")<br />
Dim YellowIcon As New Icon(Application.StartupPath & "\Icons\YellowLight.ico")<br />
Dim GreenIcon As New Icon(Application.StartupPath & "\Icons\GreenLight.ico")<br />
<br />
Dim frmNewMain As New frmMain<br />
<br />
Select Case ConnState<br />
Case "Open"<br />
Return RedIcon<br />
<br />
Case "Closed"<br />
Return GreenIcon<br />
Case Else<br />
Return YellowIcon<br />
End Select<br />
'frmNewMain.statIcon.Parent.Text = "Blablabla"<br />
<br />
End Function
Using statIcon.Icon = ConnStatusIcon(dbConn.State.ToString) where-ever needed.
It's just an excercise, I'll study the rest later.;)
|
|
|
|
|
This is what I love about programming. I thinker a bit and voila, I got it :->.
Changed it back again, but added a single line. Can you find it?
Public Sub ConnStatusIcon(ByVal ConnState As String)<br />
<br />
Dim RedIcon As New Icon(Application.StartupPath & "\Icons\RedLight.ico")<br />
Dim YellowIcon As New Icon(Application.StartupPath & "\Icons\YellowLight.ico")<br />
Dim GreenIcon As New Icon(Application.StartupPath & "\Icons\GreenLight.ico")<br />
<br />
Dim frmNewMain As New frmMain<br />
frmNewMain = frmMain.ActiveForm<br />
<br />
Select Case ConnState<br />
Case "Open"<br />
frmNewMain.statIcon.Icon = RedIcon<br />
<br />
Case "Closed"<br />
frmNewMain.statIcon.Icon = GreenIcon<br />
Case Else<br />
frmNewMain.statIcon.Icon = YellowIcon<br />
End Select<br />
<br />
End Sub
I know, I know, still a long way to go, but for now it will do
|
|
|
|
|
SilentBob101 wrote: Dim frmNewMain As New frmMain
frmNewMain = frmMain.ActiveForm
Yes, you're getting the active form, instead of creating a new one.
The 'as new frmMain' is superfluous, you're creating a form, then disposing of it right away. Doing it my way is a whole ton better, but if this gets you going for now, that's cool. Just take my advice and read up on OO before you do too much more.
SilentBob101 wrote: I know, I know, still a long way to go, but for now it will do
You're on the right track - you're trying things and asking questions to look for help with your work ( as opposed to asking people to do it for you ). Rome wasn't built in a day - you'll be fine.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi, I want to use a Button in GridView. I am adding a GridViewButtonColoumn but i dont know how to capture its OnClick event. Please help me what to do ? Thanks
kaliem
|
|
|
|
|
Just to add, I am developing windows forms application and I can not capture OnClick event on button coloumn in grid view...
kaliem
|
|
|
|
|
Hi all
when i export a file having few records, it works fine. But if i attempt to export a dataset having thousands of records, it doesn't do anything. Even, its not giving any exception.
I set a "DataSet" as a datasource of "ReportDocument" object.
Then i use this method to export the dataset records into doc file
crystalReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.WordForWindows, "D:\InventoryResults.doc")
Can anyone help?
|
|
|
|
|
Hello Guys
how can i change the font of a string ,variable... in a msgbox?
Regards
Ramy
|
|
|
|
|
As far as I know, you can't. Because a Message Box is created by Windows (Msg.cpl I think), and the font is preset.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
You can create your own messagebox and use the new messagebox instead of using the native .NET messagebox. I think you can do a quick search here, at the codeproject, and you should be able to find exactly what you need.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
|
|
Hi,
first of all sorry for my bad english.
I have a problem, I have a String like this "System.Data.DataTable" and I wont to convert this String now in a Type of this String.
That works for example with the string "System.Object", but with the String above I got Nothing.
Type.GetType("System.Data.DataTable")
For sure I can save the long version with this:
TheClass.GetType().AssemblyQualifiedName
Than also the creating is no problem, but if I understand it right than is this long version only for one PC and this is for sure shity.
Can someone help me?
mfg
|
|
|
|
|
Curse4Life wrote: For sure I can save the long version with this:
TheClass.GetType().AssemblyQualifiedName
Than also the creating is no problem, but if I understand it right than is this long version only for one PC and this is for sure *****
Please don't use profanity in the programming forums. If you must swear then please go to the Soapbox.
The long version is not tied to one PC. It will work on any PC where the appropriate assembly is installed.
|
|
|
|
|
First of all, thanks for your answer, this realy help me out.
But now I have a new problem.
Now I have create an instans of this type but now I have to fill the properties, problem is, I have all Properties in Strings, but I also have to fill integer an boolean properties of this new instans.
So I can set an value
TempObject.GetType().GetProperty(MyProperty.Name).SetValue(TempObject, MyProperty.Value, Nothing)
but how I said, a Type Exception occures because MyProperty.value is always a String.
Can you maybe help me out with this last thing.
thx
|
|
|
|
|
Curse4Life wrote: TempObject.GetType().GetProperty(MyProperty.Name).SetValue(TempObject, MyProperty.Value, Nothing)
When you do this big long line of code you lose several useful things.
1. You lose the ability to debug easily in to part of the code. You end up stepping in and out of lots of things before you get to the bit you want.
2. You lose some readability because it becomes difficult to see what each part is actually doing and in what order.
3. You lose sight of what is going in and coming out of each part. Which means you cannot see the forest for the trees.
This bit:
TempObject.GetType().GetProperty(MyProperty.Name) should return a PropertyInfo . It will tell you what this bit:
MyProperty.Value needs to be changed to in order for it to work.
You must make the string into the type that the property expects.
|
|
|
|
|
Thanks for your answer but my question is exact how make this:
"You must make the string into the type that the property expects."
I have no idea how, because I have only the value in a string format and DirectCast expect a Type but if I say:
DirectCast(MyProperty.Value, TempObject.GetType().GetProperty(MyProperty.Name).PropertyType)
then Visual Studio shows an error at this line.
Other ideas?
mfg
|
|
|
|
|
There are hundreds of types in the .NET Framework. On top of that you can create a limitless number of types yourself. You will have to find a way to convert a string into the type needed.
You might want to take a look at the subject area of serialization and deserialization - it is probably your best bet. But if you already have constraints about how the string currently looks then it may not work for you.
If you have a limited number of possible types that you know about you can set up, say, a switch statement to perform specific actions depending on the type.
Curse4Life wrote: DirectCast(MyProperty.Value, TempObject.GetType().GetProperty(MyProperty.Name).PropertyType)
And for goodness sake, please make this more readable by spliting it up over several lines.
|
|
|
|
|
i am using AxMsFlexGrid.
now i want to display boolean data column as a checkbox ! how can i do that?
please reply .
"You can do any thing you set to your mind" - theGhost_k8
|
|
|
|
|
I try to call SetParent window api.
I use this code:
Private Declare Function SetParent Lib "user32" _<br />
(ByVal hWndChild As Long, _<br />
ByVal hWndNewParent As Long) As Long<br />
<br />
Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
Dim lngStyle As Long<br />
Dim c As Object<br />
'Dim lngStatusBar As Long<br />
<br />
mobjXL = New Excel.Application<br />
mobjXL.Caption = "Main"<br />
<br />
mlngXLHwnd = FindWindow("XLMAIN", "Main")<br />
SetParent(mlngXLHwnd, Me.Handle)<br />
<br />
lngStyle = GetWindowLong(mlngXLHwnd, GWL_STYLE)<br />
<br />
lngStyle = lngStyle Xor WS_CAPTION<br />
lngStyle = lngStyle Xor WS_SIZEBOX<br />
<br />
SetWindowLong(mlngXLHwnd, GWL_STYLE, lngStyle)<br />
End Sub
When I call the function SetParent I got error:
PInvokeStackImBalance was detected
What is wrong in this line?
|
|
|
|
|
You are using Long but it should be Int32 ...
|
|
|
|
|
I change the parameter from Long to int32 but still got the error:
A call to PInvoke function 'EmbedManagedExe!EmbedManagedExe.Form1::SetParent' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Do you have any other idea how to solve the problem
|
|
|
|
|
How about...
<code>
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As Int32, _
ByVal hWndNewParent As Int32) As Int32
</code>
|
|
|
|
|
using your function declaration, I got the error:
OverflowException was unhandled.
I don't know whats wrong eith thus call?
Thanks for the help;)
|
|
|
|