Beginner Help

2»

Comments

  • Ok I figured out how to get the borderStyle to Fixed single and i also
    i figured out how to change the Backcolor.

    Textbox1.BorderStyle = BorderStyle.FixedSingle;

    Textbox1.BackColor = Color.Blue;

    But i am still stuck on changing the fontsize!
    I tried everything! and still got nothing.

    and also, I have a button for changing an image on a pictureBox
    but when i copy the page the button is useless it only works on the original page not the copy.

    Please help!!!
  • Good lord the spam is out of control on this forum now! There is like a million shoe adds!

    Anyways,

    [code]
    var m = new Form();
    m.Font = new Font(m.Font.FontFamily, 28, m.Font.Style);
    [/code]

    You have to actually put a whole new font in there - you can't just change the size of an existing font. It's sucky - but that's just the way they are set up.

    What I did up there was just used the properties from the existing font and changed the thing I wanted to change which was the size.

    As far as your other question - why don't you go ahead and post what your template looks like now and I'll let you know what I see.
  • [link=http://i207.photobucket.com/albums/bb3/Mothersweets/Joshesprogram.jpg]Here[/link] is the part of my program ive been asking questions about



    you see the button that changes the image of the picturebox? well i need to now how to copy the button as well as the code behind it.

    and i couldn't get an actual picture of my program because the computer im working on is in my basement bedroom so...you know.
  • without being able to see your code all I can suggest is to make sure the button event handler is being hooked up in the tab page template.

    [code]
    var picButton = new Button();
    this.Controls.Add(picButton);

    picButton.Click +=
    (s, e) =>
    {
    var open = new OpenFileDialog();
    if (open.ShowDialog() == DialogResult.OK)
    picButton.Image = Image.FromFile(open.FileName);

    }
    [/code]


  • sorry about that, here's the code behind the button for changing picures

    [code]Private void btnChangeImageClick(objectSender,EventArgs e)


    if (SelectPic.Showdialog() == DialogResult.OK)
    {
    Picturebox.Image = Image.FromFile(SelectPic.Filename);

    this.Text = string.Concat("Picture Viewer(b" + SelectPic.Filename+")"); [/code]

    When i make multiple copies of this tab page, and the user wants to change the picture on one of the copies will it affect the others?

    For example
    say i make 3 copies of the tabPage and on one of the copies i change the picture in the pictureBox, will the other 2 picure boxes have the same Image as the one i just canged even though i only changed one of them!

    Say it ain't so...
  • No - if the picturebox and button are both declared in the tabpagetemplate then entirely new instances of each of these will be created along with the new template. If that doesn't make sense try this out:

    [code]
    public static void Main()
    {
    ShowThreePics();
    while(true)
    Application.DoEvents();
    }

    public static void ShowThreePics()
    {
    var win1 = CreateAWindow();
    var win2 = CreateAWindow();
    var win3 = CreateAWindow();

    win1.Show();
    win2.Show();
    win3.Show();
    }

    public static Form CreateAWindow()
    {
    var win = new Form();
    var button = new Button();
    var picture = new PictureBox();
    win.Controls.Add(button);
    button.Dock = DockStyle.Bottom;
    win.Controls.Add(picture);
    picture.Dock = DockStyle.Fill;
    picture.BringToFront();

    button.Click +=
    (s, e) =>
    {
    var open = new OpenFileDialog();
    if (open.ShowDialog() == DialogResult.OK)
    picture.Image = Image.FromFile(open.FileName);
    };
    return win;
    }
    [/code]

    Run that program and look at what it's doing...

    Every time CreateAWindow is called it uses the same exact code - but an entirely new set of objects are created. Every call to CreateAWindow is completely oblivious to any previous calls and the windows that are created (and their controls) will have no interaction or knowlege of each other. So when you click the button on any one of these windows - it will only affect its own picturebox.

    This is the same concept as the template you have created, but instead of a function, you are writing a class.
  • Ok that makes me feel better.

    all right!! we are now on the last step to completing this tabPage!!

    the last step is making it so the user can NAME the new tab page

    you see the textbox right beside the New Tab button on the Picture of my program i showed you? well that is the textbox for naming the tabpage but i can't figure out how to make this happen,

    and also its the textbox for deleting a tabPage as well.

    so, user enters a name in the textbox then clicks the "add Tab" button
    and vola! a new tab with the name entered.

    user enters a name of an existing tabpage in the textbox then clicks the "Remove" button and vola! the TabPage of choice gets Exterminated.

    [link=http://i207.photobucket.com/albums/bb3/Mothersweets/Joshesprogram.jpg]HERE[/link] is my program(saves scrolling) :)
  • Because the tab page template inherits from TabPage you treat it just like you would a TabPage.

    This code should explain what you are looking for...

    [code]
    var win = new Form();
    var tab = new TabControl();
    win.Controls.Add(tab);
    tab.Dock = DockStyle.Fill;
    var t = new TabPage();
    t.Text = "Test Tab Text";
    tab.TabPages.Add(t);
    win.ShowDialog();

    foreach (var item in tab.TabPages.Cast())
    if (item.Text == "Test Tab Text")
    tab.TabPages.Remove(item);

    win.ShowDialog();
    [/code]

  • yeah i see what your talking about,

    but...im getting a headache here!
    i don't know how or where to start

    and every time i try it i get build errors!

    i try to add "Text" to the end of every statement but it's just not working.

    var text = tabpage();
    text.Text = Textbox_newTab.Text;

    I am totally doing something stupid here.

    Please tell me, how exactly do i make this work?

    i never thought that making it so you could name the tabpage could be so hard.
  • I'm not doing this to be mean - but I'm gonna let you play around this. I think what you're experiencing is a lack of familiarity with syntax.

    Just remember that everything is case sensitive. If you are not using VisualStudio or Visual C# express then start using it and start utilizing the auto-complete features and start learning how to understand what the compiler is telling you when you get errors.

    If you get frustrated just take a deep breath and just know that when you finally figure it out you'll never forget it again!

    If you are just absolutely stuck on something and you've exausted all your resources (don't forget google) - then let me know.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories