|
Greetings!
If I have a control in a split-panel, which is in a tab control, which is in a form -- how can I obtain the absolute location of the original (button) control?
Dim o As Control = LogPhotosToDbBtn
Dim x As Integer = LogPhotosToDbBtn.Location.X
Dim y As Integer = LogPhotosToDbBtn.Location.Y
While (o.Parent.Name <> "")
o = o.Parent
x += o.Location.X
y += o.Location.Y
End While
Dim p1 As Point
p1.X = x
p1.Y = y
LogFotosForm.Show()
LogFotosForm.Location = p1
X and Y are never incremented because o.Parent.Name always return "".
Is there a better way (one that actually works) of trying to do this?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Have you tried stepping through this in debug mode?
The line:
o = o.Parent will fail when you get to the form level because the form has no parent object.
That may be part of your problem ...
|
|
|
|
|
I did try to debug it, it never enters the while loop -- even tho the control is buried in several levels of parent containers.
Does o.Parent.Name return the parent's container's Name property?
If not, what does?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
watagal wrote:
Does o.Parent.Name return the parent's container's Name property?
It should. This works in Net 2002/2003.
|
|
|
|
|
watagal wrote:
Greetings!
If I have a control in a split-panel, which is in a tab control, which is in a form -- how can I obtain the absolute location of the original (button) control?
See non-working code in original post
X and Y are never incremented because o.Parent.Name always return "".
Is there a better way (one that actually works) of trying to do this?
Ok, figured out what was happening: The first parent above my button was a split panel, while the actual split panel returns the correct Name -- the Panel1 container within the split panel container does not return a Name (I guess because you can not assign it a name). Therefore, my while loop was never entered.
Here's code that does work:
Dim o As Control = uxLogPhotosToDbBtn
Dim x As Integer = 0
Dim y As Integer = 0
While (Not o Is Nothing)
x += o.Location.X
y += o.Location.Y
o = o.Parent
End While
Dim p1 As Point
p1.X = x
p1.Y = y
uxcLogFotosForm.Show()
uxcLogFotosForm.Location = p1
Thanks again for all the help,
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Now that I have accomplished what I wanted to do, Is there a faster better easier way to do this somewhat common task?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Here you go, i'll be happy to give some explanation if you want.
Imports System.Runtime.InteropServices
Public NotInheritable Class Api
<StructLayout(LayoutKind.Explicit)> _
Private Structure RECT
<FieldOffset(0)> Public left As Integer
<FieldOffset(4)> Public top As Integer
<FieldOffset(8)> Public right As Integer
<FieldOffset(12)> Public bottom As Integer
End Structure
<DllImport("User32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
End Function
''' <summary>Get the location of a control in screen coordinates.</summary>
''' <param name="control">The control who's location will be returned.</param>
''' <returns>Returns the location of the control in screen coordinates.</returns>
Public Shared Function AbsoluteLocation(ByVal control As Control) As Point
If (control Is Nothing) Then Throw New ArgumentNullException("control")
Dim rect As New rect
GetWindowRect(control.Handle, rect)
Return New Point(rect.left, rect.top)
End Function
End Class
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
Greetings!
The following code sends my program into a infinite loop.
Public Class LogFotosForm
Private Sub PreviewFotoChkBx_CheckedChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles PreviewFotoChkBx.CheckedChanged
If PreviewFotoChkBx.Checked Then
PreviewFotoChkBx.Checked = False
Me.Width = 320
Else
PreviewFotoChkBx.Checked = True
Me.Width = 450
End If
End Sub
End Class
I want to resize my form when the checkbox changes - once the checkbox is True.
Should I be using a different event?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
You're already In the "Changed" event, you don't need to change the valud a second time, doing so causes the event to be refired, and since you're toggling the value you get an infinite loop.
Take out the "PreviewFotoChkBx.Checked" lines and I think it will do what you want it to do.
|
|
|
|
|
look the problem is u r using the function PreviewFotoChkBx_CheckedChanged which handels the checkbox checked property.and in it the if condition you r changeing the property againg so function calles it self again and ur programe goes in infinite loop. insted of using checked property(handling checkedchanged)use click then it will work fine.best of luck
GET BACK 2 ME
|
|
|
|
|
OK. I have to giggle a little bit here.
Follow your code. This is the CheckedChanged event right?
Well, if the user clicks on a empty checkbox, the value of Checked changes to True , right? This fires the CheckedChanged event, not because the box was checked, but because the value of Checked was altered. Now, in your code, you check the value of Checked , then change it to the opposite of what it is set to. This fires the CheckedChanged event again because, well, you changed it! Guess what happens next...
Why are you changing the value of Checked at all? Don't! As far as I can tell, you don't need to do it for any reason. All your doing is changing the size of the form based on whether the checkbox is checked or not. Why is your code changing the checkbox value?
Eliminate the lines that are changing the checkbox:
Public Class LogFotosForm
Private Sub PreviewFotoChkBx_CheckedChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles PreviewFotoChkBx.CheckedChanged
If PreviewFotoChkBx.Checked Then
Me.Width = 320
Else
Me.Width = 450
End If
End Sub
End Class
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dooh!
I promise to think next time before asking. No I'm not blond!
Thanks to all!!
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
I have an application which contains the database connection string plus some other keys containing file paths that the user needs to use stored on key at the app.config file of the application. Is there a way that I can let the user modify the value for those paths when installing the application? this is because depending on where the application is installed the user decide where to store some files, and that's what those paths in the app.config file are for. I created a msi installer for my application, but I haven't found (and still don't know if it's possible) how to let the user set properties to the app.config file when using my installer file.
Any help will be greatly appreciated
|
|
|
|
|
You can create a Custom Action using an Installer class that will run at the end of the install. You will have to add everything you need to do this to the installer class, such as maybe showing a custom dialog, the folder browser, etc. Since app.config files for some stupid reason were never designed to allow them to be updated dynamically, there is no built-in support for modifying them, so you will have to code that manually as well.
Sorry, no example code - this is too complicated to just write out.
Search for Installer class examples and tutorials...
|
|
|
|
|
I have 2 projects: one in ASP.NET and another in VC++(VC7). ASP.NET will be placed on Server and VC++ on Client.
The client will sent data to server and receive the data from server.
I want to debug as follow:
I set client as startup project and anytime the data is sent from client to server, I want the breakpoint I set before on server will be activate.
The server now is on localhost.
How can I do that????????
Hung
|
|
|
|
|
Since the debugger can attach to only one process at a time, you'll have to launch a second Visual Studio instance and attach it's debugger to the server. One instance will debug the server, the other instance will debug your client.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I don't understand your idea. Can you explain more details! Thanks!
Hung
|
|
|
|
|
What's so hard to understand? Launch a second copy of Visual Studio! One instance of VS will debug the server part and the second instance will debug the client.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a value in in textbox1 on form1 and want to use this value on form2.
I thought it was simple and proable is but once again I am lost?
I am new to VB my background is VBA.
In VBA simply me.textbox2.text = form1.textbox1.text
|
|
|
|
|
An it could be the same also in VB.NET. The point is that your question is not very clear to me. What are form1 and form2: public, private?
You have several ways of doing it.
1) When you need it inside form2 code simply go for:
Textbox2.Text = Form1.Textbox1.Text (as you wrote, but make sure Form1 is a real object)
2) Whenever something changes in Form1
Private Sub TextBox1_Changed(...) handles TextBox1.Changed ' (not sure if it's changed the event name, better double check)
Form2.TextBox2.Text = TextBox1.Text ' (again make sure Form2 is a real object)
End Sub
Hope it helps.
If it doesn't please state the problem/error
|
|
|
|
|
try simply:
Me.textbox2.Text = textbox1.Text
Patrice
|
|
|
|
|
The numerical value I want to use on Form1 = frmSnow is a textbox = tbxSL
The value of the textbox is calculated based on user selections on Form1.
I want to use the value on Form2 = frmDrift1 to perform other calculations.
Code Line
Me.tbxDensity.Text = frmSnow.tbxSL.text
Problem
Reference to a Non-Shared Member requires a Object Reference
|
|
|
|
|
Thanks for Help
I think I got it
I never created an instance of the form.
|
|
|
|
|
does anyone know how to trap HTML opening & closing HTML tags within string using regular expression>
|
|
|
|
|
hi every one , plz help me to crear or to call ms agent in application in VB 6.0.
i want to show as help asistant in ms office.
plz reply me at ambujpande@gmail.com
regards
Ambuj Pande
|
|
|
|