Post: C# Changing image help
02-07-2017, 12:17 AM #1
KrazyKandy
I am error
(adsbygoogle = window.adsbygoogle || []).push({}); Here is what I'm doing to create multiple picture boxes
You must login or register to view this content.
so the tabpage is scrollable, but I'm confused on how to change each picture boxes image. I have tried
    Images[0].Image = ----
and Images[1].Image = ----

and so on, but that doesnt work.
02-07-2017, 02:12 AM #2
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
Here is what I'm doing to create multiple picture boxes
You must login or register to view this content.
so the tabpage is scrollable, but I'm confused on how to change each picture boxes image. I have tried
    Images[0].Image = ----
and Images[1].Image = ----

and so on, but that doesnt work.


What is the data type for the resource? If that is being set as a string that could be the problem

Anyways this should help:
You must login or register to view this content.
02-07-2017, 03:16 PM #3
KrazyKandy
I am error
Originally posted by Oneup View Post
What is the data type for the resource? If that is being set as a string that could be the problem

Anyways this should help:
You must login or register to view this content.


Shouldn't be a string, the picture is showed is all I'm doing
02-07-2017, 10:06 PM #4
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
Shouldn't be a string, the picture is showed is all I'm doing


Can you post your project source code?
02-07-2017, 10:29 PM #5
KrazyKandy
I am error
Originally posted by Oneup View Post
Can you post your project source code?

I'm sorry but there really is no point, this is all I have in it along with the images
You must login or register to view this content.
You must login or register to view this content.
02-07-2017, 10:35 PM #6
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
I'm sorry but there really is no point, this is all I have in it along with the images
You must login or register to view this content.
You must login or register to view this content.


There is a huge point in it. I dont want to have to type shit out because all you provided was an image. You can't copy and past that in. Not to mention Materialskin isn't a built in, I don't know how that behaves.
02-07-2017, 10:44 PM #7
KrazyKandy
I am error
Originally posted by Oneup View Post
There is a huge point in it. I dont want to have to type shit out because all you provided was an image. You can't copy and past that in. Not to mention Materialskin isn't a built in, I don't know how that behaves.


Alright damn.. sorry didnt know :/
You must login or register to view this content.
02-07-2017, 11:52 PM #8
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
Alright damn.. sorry didnt know :/
You must login or register to view this content.


I am retarded, my original post was when I was half asleep and I never bothered to go back and re-read your problem. Sorry about that. I thought the image wasn't loading.

So you are right I really didn't need the code. However having it made this easier so thanks Smile.

Here's the updated Code.

    
using System;
using System.Windows.Forms;
using MaterialSkin;
using MaterialSkin.Controls;
using System.Drawing;
using System.Collections;
using System.Resources;
using System.Collections.Generic;

namespace MaterialSkinExample
{
public partial class MainForm : MaterialForm
{
private readonly MaterialSkinManager materialSkinManager;
public MainForm()
{
InitializeComponent();

// Initialize MaterialSkinManager
materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
materialSkinManager.ColorScheme = new ColorScheme(Primary.Indigo700, Primary.Indigo800, Primary.Indigo500, Accent.LightBlue100, TextShade.WHITE);
}


private List<System.Drawing.Bitmap> DumpImagesToList()
{
ResourceManager resxIMages = Properties.Resources.ResourceManager;
ResourceSet resxSet = resxIMages.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);
IDictionaryEnumerator resxEnum = resxSet.GetEnumerator();
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
while (resxEnum.MoveNext())
{
if (resxEnum.Value is Bitmap)
{
images.Add((Bitmap)resxEnum.Value);
}
}
return images;

}

private void MainForm_Load(object sender, EventArgs e)
{

List<System.Drawing.Bitmap> images = DumpImagesToList();
PictureBox[] Images = new PictureBox[images.Count -1];
for (int i = 0; i <images.Count -1; i++)
{
Images[i] = new PictureBox();
Images[i].Name = "image_" + i.ToString();
Images[i].Location = new Point(-10, tabPage1.Controls.Count * 150);
Images[i].Size = new Size(219, 137);
Images[i].SizeMode = PictureBoxSizeMode.Zoom;

//Images[i].Image = MaterialSkinExample.Properties.Resources.W_2013_267_4000_LUX;
Images[i].Image = images[i];
Images[i].Visible = true;
tabPage1.Controls.Add(Images[i]);
}
}

private void MainForm_Click(object sender, EventArgs e)
{
}
}
}
02-08-2017, 12:06 AM #9
KrazyKandy
I am error
Originally posted by Oneup View Post
I am retarded, my original post was when I was half asleep and I never bothered to go back and re-read your problem. Sorry about that. I thought the image wasn't loading.

So you are right I really didn't need the code. However having it made this easier so thanks Smile.

Here's the updated Code.

    
using System;
using System.Windows.Forms;
using MaterialSkin;
using MaterialSkin.Controls;
using System.Drawing;
using System.Collections;
using System.Resources;
using System.Collections.Generic;

namespace MaterialSkinExample
{
public partial class MainForm : MaterialForm
{
private readonly MaterialSkinManager materialSkinManager;
public MainForm()
{
InitializeComponent();

// Initialize MaterialSkinManager
materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
materialSkinManager.ColorScheme = new ColorScheme(Primary.Indigo700, Primary.Indigo800, Primary.Indigo500, Accent.LightBlue100, TextShade.WHITE);
}


private List<System.Drawing.Bitmap> DumpImagesToList()
{
ResourceManager resxIMages = Properties.Resources.ResourceManager;
ResourceSet resxSet = resxIMages.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);
IDictionaryEnumerator resxEnum = resxSet.GetEnumerator();
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
while (resxEnum.MoveNext())
{
if (resxEnum.Value is Bitmap)
{
images.Add((Bitmap)resxEnum.Value);
}
}
return images;

}

private void MainForm_Load(object sender, EventArgs e)
{

List<System.Drawing.Bitmap> images = DumpImagesToList();
PictureBox[] Images = new PictureBox[images.Count -1];
for (int i = 0; i <images.Count -1; i++)
{
Images[i] = new PictureBox();
Images[i].Name = "image_" + i.ToString();
Images[i].Location = new Point(-10, tabPage1.Controls.Count * 150);
Images[i].Size = new Size(219, 137);
Images[i].SizeMode = PictureBoxSizeMode.Zoom;

//Images[i].Image = MaterialSkinExample.Properties.Resources.W_2013_267_4000_LUX;
Images[i].Image = images[i];
Images[i].Visible = true;
tabPage1.Controls.Add(Images[i]);
}
}

private void MainForm_Click(object sender, EventArgs e)
{
}
}
}


You're a legend, sorry if I was a bit confusing on my part. Thank you so much Smile
02-08-2017, 12:09 AM #10
Default Avatar
Oneup
Guest
Originally posted by KrazyKandy View Post
You're a legend, sorry if I was a bit confusing on my part. Thank you so much Smile


I would suggest renaming the List Variable in MainForm_Load. I just realized that while it is lowercase and seen as different, that will get confusing.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo