Grabbing Data From Classes

Discussion in 'C#' started by x64, Apr 19, 2007.

  1. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    /Puts noob hat on.

    Alright, this is probably the biggest n00b question you will get from me. How can I grab and receive values from different classes? Honestly, I've never had to deal with classes until now. Here is my situation:

    I have created and completed a Notepad clone, but with many more features. I'm just cleaning code and adding even more now that it doesn't need to be shown to a college. Anyways, I want to allow the user to define their default font, richtextbox background color, word wrap enabled/disabled, number of tabs, etc... So, I created "public partial class Options : Form" (Nice copy and paste feature.). Ok so in this partial class, whatever the heck that is, I have functions for each object in this form. For example, I have a maskedtextbox where the user will type in the number of maximum tabs that can be opened at once, I can put this into an int but then when I go back to my main application partial class I have no idea how to retrieve that int and use it to affect the maximum number of tabs that can be opened.

    I would have searched Goggle and this form for the answer but I don't know what it's called.

    Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    First of all your options calls does not need to be deriving from the Form class because Options is not having a relationship with the Form.

    Now getting to your Questions here is the best way to be doing that in your scenario.

    1. You can have a property to whatever stored in the variable is exposed as public method.
    2. Now have an Object of your Options class in the Form class where you want to create the tabs.
    3. Access the property by the object.

    Now your solution can be made more generic like
    • You can have some static property to get the data from the class.
    • You can have the singleton class of Options so you dont create nultiple objects of it every where.
     
  3. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    Sorry for a late response, I've been busy.

    Alright. I think I am kind of confused and because of that I think I explained it wrong. Let me give it another shot, ok? If I remove the "Form" part of the class it doesn't work, as you see in the screen shot below it is a form called Options with options that the user will be able to define as defaults. Take the first text box for example, lets say the user types in 15 for the maximum number of tabs and I place that into an int i when the OK button is pushed. Now, how would I get that value int i into another Class : Form and apply that to make it limit the tabs to 15 for the tab control?

    Sorry if this is confusing to you, I don't know how to explain it :confused:.

    Thanks

    P.S: Error while trying to attach the .jpeg image to the post on this board. I didn't post the image threw another site, I don't know if that counts as linking to another site.
    Code:
    [b]Warning[/b]: move_uploaded_file(attachments/0fa2824bc662c6072d9e638e7e0f983f): failed to open stream: Permission denied in [b]/includes/functions_file.php[/b] on line [b]274[/b]
     
    [b]Warning[/b]: move_uploaded_file(): Unable to move '/tmp/phprrPdDs' to 'attachments/0fa2824bc662c6072d9e638e7e0f983f' in [b]/includes/functions_file.php[/b] on line [b]274[/b]
     
    [b]Warning[/b]: filesize(): Stat failed for attachments/0fa2824bc662c6072d9e638e7e0f983f (errno=2 - No such file or directory) in [b]/includes/functions_file.php[/b] on line [b]286[/b]
    
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    We have taken a note of the error and will post here when we fix the issue. The issue is with the file permission on the new server we have moved on.

    Apart from that I think once you attach the query will become clear.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The problem is solved and thanks for pointing that out. Now you can try explain with the screenshot.
     
  6. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    Alright, the screen shot should be attached.
     

    Attached Files:

  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Still my answer remains the same but I will try to explain with respects.

    15 is stored in the class variable int and not to a locale variable of the function in that class and now you can have my first option like

    1. You can have a property to whatever stored in the variable is exposed as public method.
    2. Now have an Object of your Options class in the Form class where you want to create the tabs.
    3. Access the property by the object.

    Now I will tell you the sample run.

    Say we have some static members in the class called Options.
    Code:
    class Options
    {
      static int i;
      // Add a property for i
    }
    
    Now have this class access and set when OK is pressed and get this i when you need it. You can now have as many options you like to be available to all the classes globally as the properties are static
     
  8. x64

    x64 New Member

    Joined:
    Apr 16, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    St.Paul Minnesota, USA
    I'm very sorry. I understand what you are saying, I really do! But do you happen to have a tutorial on how to do this that you can recommend? When I try to code what you say to do I find myself not able to do it. I have never attempted/seen code to do this it's kind of like walking around a forest blind folded.

    Sorry for the trouble, and thanks for all the help.
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Then you need to go the book way because what I am saying is basics of C#. Any reasonable book will do the trick for you.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice