Results 1 to 2 of 2

Thread: trouble

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2012
    Posts
    20

    trouble

    ok what i was trying to do here is send the info to the label2.text and it just wont i was wondering if i was missing a piece of code or put it somewhere i shouldnt have idk here is the code

    Code:
    private void button7_Click(object sender, EventArgs e) { }
                string GetProductId()
                {
                    RegistryKey localMachine = null;
                    if (Environment.Is64BitOperatingSystem)
                    {
                        localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
                    }
                    else
                    {
    
                        localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
                    }
    
                    RegistryKey windowsNTKey = localMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion");
                    return windowsNTKey.GetValue("ProductId").ToString() ;
                    label2.Text = GetProductId();
    
                }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: trouble

    Why are you calling GetProductId inside GetProductId? Regardless, that last line is never actually going to be executed because it comes after the return statement. I'm guessing that that last line should actually be inside the Button's Click event handler. When the Button is clicked you call the method and assign the result to the Text of the Label.

    By the way, that's an inspired thread title. You may as well just leave it blank because that's completely useless. The title is supposed to describe the topic of the thread so that we don't have to waste our time opening every single one to see which ones are relevant to us. Please do us the courtesy of providing a meaningful, descriptive thread title.

Posting Permissions

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



Click Here to Expand Forum to Full Width