Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Open a form on socket receive

Open a form on socket receive

Scheduled Pinned Locked Moved .NET (Core and Framework)
sysadminsecurityhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gian
    wrote on last edited by
    #1

    Hello, i'm developing a Client/Server application and i've to create a Administration Form that opens only when the client is logged like administrator. When i click on the admin button the client request authorization to the server. the server checks if it's an admin and if another admin is logged with admin panels opened, after that sends him a message telling him he can or cannot open the admin form. On the receive of the message i try to open the form but doesnt work. In a modal way the form appears but nothing is displayed in it and i cant close/do nothing. using the form in a modeless way with .Show() only it's the same. So i've tried to make it mdi child of the main form but the program says it cannot make the form parent of something that is in another thread. Is there a way to solve this problem? Thank you very much

    F 1 Reply Last reply
    0
    • G Gian

      Hello, i'm developing a Client/Server application and i've to create a Administration Form that opens only when the client is logged like administrator. When i click on the admin button the client request authorization to the server. the server checks if it's an admin and if another admin is logged with admin panels opened, after that sends him a message telling him he can or cannot open the admin form. On the receive of the message i try to open the form but doesnt work. In a modal way the form appears but nothing is displayed in it and i cant close/do nothing. using the form in a modeless way with .Show() only it's the same. So i've tried to make it mdi child of the main form but the program says it cannot make the form parent of something that is in another thread. Is there a way to solve this problem? Thank you very much

      F Offline
      F Offline
      Fade Amit BS
      wrote on last edited by
      #2

      The windows forms will behave abnormally when you try to access them forom a different thread then they are, and as you are probably getting the communication message on another thread you cannot directly control the forms BUT! the .net developers have been kind enough to porvide us with the 'Invoke' method, which is a member of each and every control (forms, buttons etc.) this allows you to tell the control (form for this matter) to do something in it's own thread what you need to do is to create a method (sub) that creates the new form and assigns it to a variable, that method should be located in your startup form, or any other form you want to use. private AdminFormMember as AdminForm Private Sub CreateNewForm() AdminFormMember= New SocketControlForm() AdminFormMember.Show() End Function and Create a delegate to it like so private delegate sub CreateNewFormDlg() and call it from your code when you want to create to new form using the 'Invoke' method, like so: If (OpenAdminForm = True) then ' Creating a delegate instance dim CreationDelegate as new CreateNewFormDlg() ' invoking it from the main form's thread ! MainForm.Invoke(CreationDelegate) end if That's it, not too complicated and it works, trust me ;) Fade (Amit BS)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups