[RESOLVED] textbox focus problem-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 42

Thread: [RESOLVED] textbox focus problem

  1. #1

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Resolved [RESOLVED] textbox focus problem

    after the picturebox is dropped down , the textbox then no longer receives any focus

    here is the demo
    hoss.zip

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: textbox focus problem

    No offense, but I am not familiar with your posts enough to trust the zip download. Can you post the actions in your code where 'the picturebox is dropped down' (I don't know what that means.)? And maybe a screenshot of your form?

    Sammi

  3. #3
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,065

    Re: textbox focus problem

    The project consists of a single form with no code.
    There is a single control on the form, which is a UC(user control).

    There are no other dependencies or References
    That is the good news

    The bad news is I have never worked with the code within a UC
    (Except once to solve a UC message box, that ran on everything except W10. Still patting myself on the back for solving that one)

    So it probably pays for the OP to mention - some one familiar with UC's should have a look at this.

    Rob

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Posts
    1,065

    Re: textbox focus problem

    Here is the code in the UC (actually this is all of the code in the project) -
    Code:
    Const SWP_NOSIZE As Long = &H1
    Const SWP_NOMOVE As Long = &H2
    Const SWP_NOZORDER As Long = &H4
    Const SWP_NOREDRAW As Long = &H8
    Const SWP_NOACTIVATE As Long = &H10
    Const SWP_NOOWNERZORDER As Long = &H200
    Const HWND_TOPMOST As Long = -1
    Const GWL_STYLE As Long = (-16)
    Const GWL_EXSTYLE As Long = (-20)
    Const HWND_DESKTOP As Long = &H0
    Const WS_CHILD As Long = &H40000000
    Const WS_VISIBLE As Long = &H10000000
    Const SBS_SIZEBOXTOPLEFTALIGN As Long = &H2&
    Const SBS_SIZEBOXBOTTOMRIGHTALIGN As Long = &H4&
    Const SBS_SIZEBOX As Long = &H8&
    Const SBS_SIZEGRIP As Long = &H10&
    Dim SizeGripHandle As Long
    Const WS_EX_APPWINDOW As Long = &H40000
    Const WS_EX_TOOLWINDOW As Long = &H80
    
    
    Const HWND_NOTOPMOST = -2
    Const HWND_TOP = 0
    Private Declare Function SetCapture Lib "user32.dll" (ByVal hwnd As Long) As Long
    Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type
    Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, ByRef lpPoint As POINTAPI) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal CX As Long, ByVal CY As Long, ByVal wFlags As Long) As Long
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExW" (ByVal dwExStyle As Long, ByVal lpClassName As Long, ByVal lpWindowName As Long, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function BringWindowToTop Lib "user32.dll" (ByVal hwnd As Long) As Long
    
    
    Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    
    
    
    Public Sub TestDropDownClient(DropDownClient As PictureBox)
    
    
        DropDownClient.Visible = False
        DropDownClient.BorderStyle = 0
        SetWindowLong DropDownClient.hwnd, GWL_EXSTYLE, GetWindowLong(DropDownClient.hwnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW And Not WS_EX_APPWINDOW
        SetWindowLong DropDownClient.hwnd, GWL_STYLE, GetWindowLong(DropDownClient.hwnd, GWL_STYLE) Or &H80000
        Dim P As POINTAPI
        ClientToScreen UserControl.hwnd, P
        SetParent DropDownClient.hwnd, HWND_DESKTOP
        MoveWindow DropDownClient.hwnd, P.X, P.Y + UserControl.ScaleHeight, UserControl.ScaleWidth, 100, 1
    
        SetWindowPos DropDownClient.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE Or SWP_NOOWNERZORDER
        DropDownClient.Visible = True
        
        
        Dim SizeGripHandle As Long
        SizeGripHandle = CreateWindowEx(0, StrPtr("ScrollBar"), StrPtr(vbNullString), WS_CHILD Or WS_VISIBLE Or SBS_SIZEBOX Or SBS_SIZEBOXBOTTOMRIGHTALIGN Or SBS_SIZEGRIP, 0, 0, 0, 0, DropDownClient.hwnd, 0, App.hInstance, ByVal 0&)
    
    
    End Sub
    
    Private Sub Command1_Click()
    TestDropDownClient Picture1
    End Sub
    Attached Images Attached Images  
    Last edited by Bobbles; Sep 8th, 2017 at 08:25 AM. Reason: added image

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: textbox focus problem

    That's not me!!!!

  6. #6
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Nor me .. but I'll tag along for the ride and maybe learn something

  7. #7
    Addicted Member
    Join Date
    Apr 2017
    Posts
    181

    Re: textbox focus problem

    The zip file is bad

  8. #8

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    I uploaded it in zip extension because the uploader never let me upload rar files and I dont know why .
    simply it is a user control which has a picturebox which I need it to float outside the usercontrol like a pop-up window . I set the parent of the picturebox to HWND-DESKTOP and this is the problem. once set , the textbox in the picturebox never gets the focus even by mouse .

    any help

  9. #9
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Hosam

    Is the code that Bobbles shows in post #4 the code you put into the zip file?

    Spoo

  10. #10

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    yes it is

  11. #11
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Good ,, that's a start.
    Now we just need somebody who know's what's going to make a guest appearance ..

    Spoo

  12. #12

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    I will simplify the code now , just add a usercontrol with command1 and picture1 . Add new textbox to the picturebox . consider changing picturebox color or user control color to distinguish between them because the will be layered one over one . Before clicking the command, the textbox behaves so normally . Once the command is clicked , the textbox will no longer receive any manual focus by mouse or by code.

    here is all the code

    this code makes the picturebox as a new window

    Code:
    Option Explicit
    
    Private Const WM_SETFOCUS = &H7
    Const GWL_STYLE As Long = (-16)
    Const GWL_EXSTYLE As Long = (-20)
    Const WS_EX_TOOLWINDOW As Long = &H80
    
    
    
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    
    Private Sub Command1_Click()
    
    SetParent Picture1.hwnd, 0
    SetWindowLong Picture1.hwnd, GWL_EXSTYLE, (GetWindowLong(Picture1.hwnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW)
    
    Picture1.ZOrder 0
    UserControl.ScaleMode = 3
    Picture1.Visible = True
    
    SendMessage Picture1.hwnd, WM_SETFOCUS, 0, 0
    
    End Sub

  13. #13
    Addicted Member
    Join Date
    Apr 2017
    Posts
    181

    Re: textbox focus problem

    Looks like you put a .zip extension on a .rar file


    Clicking on button causes the picturebox with the textbox to appear in the upper left corner of the screen. I don't see any code that positions the UC

  14. #14

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    yes , no problem with positionning. forget abut attachment . all the code is in post #12 . and my problem is the focus of the textox

  15. #15
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Hosam

    I'm going out on a limb here, but in your sub ..
    Code:
    Private Sub Command1_Click()
        SetParent Picture1.hwnd, 0
        SetWindowLong Picture1.hwnd, GWL_EXSTYLE, (GetWindowLong(Picture1.hwnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW)
        Picture1.ZOrder 0
        UserControl.ScaleMode = 3
        Picture1.Visible = True
        SendMessage Picture1.hwnd, WM_SETFOCUS, 0, 0
    End Sub
    .. I don't see any reference to Text1.
    1. Might it be that you have to set it's .Visible property to True?
    2. Also, did you try Text1.SetFocus?


    Spoo

  16. #16

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    if you click on the textbox , does the cursor show ? does it get focus ?

  17. #17
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Hosam

    if you click on the textbox , does the cursor show ? does it get focus ?
    If you're addressing that to me, you're asking the wrong guy.

    1. I haven't tried your code
    2. What are your answers to those questions
    3. You didn't answer my questions in post #15.

    Spoo

  18. #18

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    my answer is :: none of these methods worked . this is on the code level . but when you even try to click on the textbox it does not also get focus .

  19. #19
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: textbox focus problem

    Where is your usercontrol? You said to ignore the zip file (attachment). but obviously, in the command1 click event, i need a UC your created.

  20. #20

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    this code is in a user control . and it is the whole code

  21. #21
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    SetParent is breaking the behavior. Whatever you are attempting, you may need to consider an alternate way.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  22. #22

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    Quote Originally Posted by LaVolpe View Post
    SetParent is breaking the behavior. Whatever you are attempting, you may need to consider an alternate way.
    what about setting the owner ?

    as found in this demo

    http://www.vbforums.com/showthread.p...=1#post5211495
    Last edited by Hosam AL Dein; Sep 8th, 2017 at 05:23 PM.

  23. #23
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    Can I ask why you are trying to remove a control (picturebox) from your project and pinning it to the desktop? Maybe better understanding the purpose will help us provide better suggestions?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    what about setting the owner ?

    as found in this demo

    http://www.vbforums.com/showthread.p...=1#post5211495

  25. #25

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    Quote Originally Posted by LaVolpe View Post
    Can I ask why you are trying to remove a control (picturebox) from your project and pinning it to the desktop? Maybe better understanding the purpose will help us provide better suggestions?
    I have a usercontrol , its function is to read some recordset and display it in a lsit view . and this pop up will help me to add the search function for the fields of the recordset . it may have more than 30 textboxes .so it is an area problem

  26. #26

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    the form concept will require more performance load beacuase it will have to recall some usercontrl methods again . anyway . I just first want to make sure that using the picturebox is a closed way and then we will discuss the form method if you dont mind lavolpe . I hope this problem is solved . it is a headache

  27. #27
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: textbox focus problem

    Hosam

    As I mentioned, I know diddly-squat about UC's, but I created the following in the IDE

    1. Command1
    2. PB1
    3. TextBox manually placed inside of PB1 .. named Text3(2) .. but don't ask why ..

    When I click the TextBox, I get this ..

    Name:  UC1.png
Views: 34
Size:  1.9 KB

    ... and focus moves from the CB to the TextBox and the cursor "flashes"

    Of course, this is NOT what you are doing, but I just wanted to establish a starting point .. this is what you are expecting, right?

    EDIT-1

    Oops .. I didn't expect the cursor to be captured by Paint.
    I manually changed the text and added a "|", but now I see that the "real" cursor appears
    on the second line of the TextBox. Sorry for any confusion.

    Spoo
    Last edited by Spooman; Sep 8th, 2017 at 05:38 PM.

  28. #28
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    @Hosam...

    This will enable the textbox, but it prevents being able to access the parent form. If the button, picbox & textbox were part of the form instead and the code was called, the same happens, but you could tab from the textbox back to the form (command button) which enables the form to be accessed normally. Guess what I'm trying to say, is to use the code below, you'll need a way to move the picbox back to the usercontrol from the picbox. If stuck, you'll want to close the form via the IDE toolbar STOP button.
    Code:
    SetWindowLong Picture1.hwnd, GWL_STYLE, (GetWindowLong(Picture1.hwnd, GWL_STYLE) Or WS_POPUP)
    SetWindowLong Picture1.hwnd, GWL_EXSTYLE, (GetWindowLong(Picture1.hwnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW)
    SetParent Picture1.hwnd, 0
    Personally, I think a different approach may be worth pursuing if you are having this much trouble early on.

    FYI: Const WS_POPUP As Long = &H80000000
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  29. #29

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    As I mentioned, I know diddly-squat about UC's, but I created the following in the IDE
    thanks so much spoo for trying to help , but as you said it is not exactly the problem . thanks again

    This will enable the textbox, but it prevents being able to access the parent form. If the button, picbox & textbox were part of the form instead and the code was called, the same happens, but you could tab from the textbox back to the form (command button) which enables the form to be accessed normally. Guess what I'm trying to say, is to use the code below, you'll need a way to move the picbox back to the usercontrol from the picbox. If stuck, you'll want to close the form via the IDE toolbar STOP button.
    Code:
    SetWindowLong Picture1.hwnd, GWL_STYLE, (GetWindowLong(Picture1.hwnd, GWL_STYLE) Or WS_POPUP)
    SetWindowLong Picture1.hwnd, GWL_EXSTYLE, (GetWindowLong(Picture1.hwnd, GWL_EXSTYLE) Or WS_EX_TOOLWINDOW)
    SetParent Picture1.hwnd, 0
    Personally, I think a different approach may be worth pursuing if you are having this much trouble early on.

    FYI: Const WS_POPUP As Long = &H80000000
    thank you lavolpe , it works fine for now. but I am awfully sorry , I think I could not get your point clearly about the considerations with this code .

    excuse me again for misunderstanding

  30. #30
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    When I clicked the command button, I could no longer access the form. It was as if it was disabled. I'd think you would have the same problem. The only way I could close the form was to click the STOP button on the IDE toolbar.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  31. #31

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    yes , I have just noticed this issue . so , is it a dead end for this approach now ? cant this be done in any other way lavolpe ? not including a form .

  32. #32
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    I think a form is the best solution for several reasons:
    1 - makes sense to me
    2 - you should be able to show it as "owned" by the parent form. This will make it minimize when parent is minimized; prevents it from going behind the parent form
    3 - if user closes the parent form, all owned forms are closed as well
    4 - lots of real estate for what you need

    Above being said, I've created dozens of usercontrols, but never one that contained a form.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  33. #33

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    ok , lets say
    1- I have a form . say form1
    2- this form has 2 UCs . UC1 and UC2
    3- both UCs popped-up another form (replacement for the picturebox)

    I want a method to the replacement form is that now it deals with UC1 which is placed in form1. I mean returning them as objects to the form to be able to put this code in the replacement form :: say ::

    Code:
    form1.uc1.backcolor=vbred
    or

    Code:
    call form1.uc1.startanything
    or any other method
    Last edited by Hosam AL Dein; Sep 8th, 2017 at 06:51 PM.

  34. #34

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    more clearly

    in the usercontrol command1 which is used to pop-up the form

    Code:
    dim frm as new replacementform
    
    frm.show
    now tell the form that it is dealing with UC1 in form1 and pass them to the form as frmobject and ucobject

    to be later able to write this code in the replacementform
    Code:
    frmobject.ucobject.backcolor=vbred

  35. #35
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    Am not sure I fully understand.
    The command button in the UC may have code like this:
    Code:
    dim frm as new replacementform
    
    frm.OwnerUC = Me
    frm.show , UserControl.Parent ' << owned by parent form.
    ' If UC is in another UC, above may error, so may need to code around that if applicable
    The form can have a public property where you can identify which UC called it...
    Code:
    ' in the form declarations section
    Private m_MyUC As Object
    
    ' then this property added to your form
    Friend Property Let OwnerUC(Value As Object)
        Set m_MyUC = Value
    End Property
    
    ' in your form's unload event: Set m_MyUC = Nothing
    
    ' now somewhere in  your code: m_MyUC.BackColor = vbRed
    The above is just one possible solution if I understood your question correctly
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  36. #36

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    here is a demo . it produces an error . what is wrong here ?
    replacement.zip

  37. #37
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    Change: OwnerFRM.OwnerUC.BackColor = vbRed
    To: m_MyUC.BackColor = vbRed

    OwnerFRM is the parent form. To reference a control from a form, you need to use the format: OwnerFRM.Control. For example a textbox: OwnerFRM.Text1. Alternate method is to reference a form's control by its name via: OwnerFRM.Controls("name")

    Not sure why you would need to cache a reference. It can be retrieved from:
    m_MyUC.Parent
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  38. #38

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    maybe the complete project will make it more clear .

    now I have three UCs on the form . each one is calling its form . the button on the form should throw its effect on only the control which called it and this does not happen
    replacement.zip

    I need every form to affect the control which called it to load

    the getcontrolfrom hwnd needs more improvements I know , but it is jst because I wanted to pass the control as an object to the form . if there is any better solution , it would be nice

    and the reason why I want the form and the control to be passed is because there might be two forms with many UCs , so , I want to access the control like this
    Code:
    someform.somecontrol.backcolor
    Last edited by Hosam AL Dein; Sep 8th, 2017 at 09:12 PM.

  39. #39
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,730

    Re: textbox focus problem

    Replace: frm.OwnerUC = GetControlFromhWnd(UserControl.hWnd)
    with: frm.OwnerUC = Me

    ^^ Your are setting the form's property from within the usercontrol. Just pass the usercontrol's own reference. Don't make it harder than it needs to be

    You also had your calls reversed in the popup form. Swap OwnerUC with OwnerFRM in command1_click.

    Note: If your intent is to change the color of the popup form, then just use Me in the popup form's code, not OwnerFRM
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  40. #40

    Thread Starter
    Lively Member Hosam AL Dein's Avatar
    Join Date
    Jul 2017
    Location
    Egypt , Cairo
    Posts
    126

    Re: textbox focus problem

    no , lavolpe . you dont get what I mean . I find it hard to communicate due to many things related to my language . ok . forget about all of this lavolpe ,

    I need each form to paint the control which initiated it . load the 3 forms and you will find that all paint the same UC.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.