|
What's to understand? His question is to blatently leech code off of someone else and turn it in as his own work.
|
|
|
|
|
Hi,
i am making a small image viewer application by using C#. I created a user control which will take the image input and draw it by using the override method OnPaint, and then add the control into the flowlayoutpanel. In FlowLayoutPanel, i set the autoscroll = true. Everything works fine, except when i scroll down the panel, the images become vague and the program has to repaint them. Please look at the screenshot for more details
http://i979.photobucket.com/albums/ae280/jasonvoorheeszzz/bug.png[^]
Have anyone got the suggestion to fix it?
|
|
|
|
|
maybe you are running out of memory somehow.
are those basically large pictures drawn at a very small scale? if so, you should create smaller versions, and use those to do your painting.
we'll need more information, some numbers and some code to offer actual help.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you for replying me. I dont think this is the problem of the memory usage coz i checked it carefully.
This is the code my ImageArea class (user control):
public Image LoadImage()
{
Image tmpImage = Image.FromFile(imageName);
Bitmap tmpBitmap = new Bitmap(100, 100);
Graphics graphics = Graphics.FromImage((Image)tmpBitmap);
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(tmpImage, 0, 0, 100, 100);
tmpImage.Dispose();
graphics.Dispose();
return (Image)tmpBitmap;
}
protected override void OnPaint(PaintEventArgs e)
{
Image tmpImage = LoadImage ();
Graphics graphics = e.Graphics;
graphics.DrawImage(tmpImage, 0, 0);
tmpImage.Dispose();
graphics.Dispose();
}
When i press the button ok in the openFileDialog, it will run the AddImageArea function to add the control to the flowLayoutPanel
And this is the code of AddImageArea
public ImageArea AddImageArea(string filename)
{
ImageArea pbObj = new ImageArea();
pbObj.ImageName = filename;
pbObj.Width = 100;
pbObj.Height = 100;
pbObj.ImageName = filename;
pbObj.BorderStyle = BorderStyle.FixedSingle;
return pbObj;
}
|
|
|
|
|
bubuzzz wrote: graphics.Dispose();
that is wrong.
You should dispose of those objects that offer a Dispose() method if you created them (by calling new, or a method with "Create" in the name). you should not dispose of objects others created, such as the Graphics you borrowed from PaintEventArgs.
bubuzzz wrote: return (Image)tmpBitmap;
is OK, however IMO you don't need the cast.
One bad thing is you are loading and resizing all those images inside OnPaint(); OnPaint() should be fast (most of the time), so you would do better by keeping the small images in memory, maybe in a Dictionary (filename, smallImage), which you could load beforehand, or when necessary, but not every time the system decides it has to (re)paint.
Warning: Dictionaries tend to grow all the time, depending on the nature of your app, you may want to take care of that.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi all,
One System having Oracle database with RH Linux OS. in one more system having WinXP OS.
I want to access Oracle database through WinXP System.
How can I achive this?
|
|
|
|
|
by magic... you need to make a magic incantation on oracle database with one of the magic stick (C#, Java, C++, etc) or with one of Oracle's free IDE (e.g. SQLdeveloper)... then you will be able to for feel you're destiny!!!
|
|
|
|
|
In the code how can we check for below errors
i) DB files not available
ii) DB is corrupted
iii) Driver errors.
|
|
|
|
|
Just try to access it and display an the Exception.Message if one is thrown -- what else would you try to do?
|
|
|
|
|
Hi Experts,
What i am trying to achieve here is a bit tricky. Let me brief on a little background first before going ahead.
I am aware that we can use a enum as a type to a parameter of a method. For example I can do something like this (a very basic example)
namespace Test
{
class DefineEnums
{
public enum MyEnum
{
value1 = 0,
value2 = 1
}
}
class UseEnums
{
public void UseDefinedEnums(DefineEnums.MyEnum _enum)
{
}
public void Test()
{
UseDefinedEnums(DefineEnums.MyEnum.value1);
}
}
}
What i need to do is create a dynamic Enum and use that as type in place of DefineEnums.MyEnum mentioned above.
I tried the following.
1. Used a method which i got from the net to create a dynamic enum from a list of strings. And created a static class which i can use.
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace Test
{
public static class DynamicEnum
{
public static Enum finished;
static List<string> _lst = new List<string>();
static DynamicEnum()
{
_lst.Add("value1");
_lst.Add("value2");
finished = CreateDynamicEnum(_lst);
}
public static Enum CreateDynamicEnum(List<string> _list)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName aName = new AssemblyName("TempAssembly");
AssemblyBuilder ab = currentDomain.DefineDynamicAssembly(
aName, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
EnumBuilder eb = mb.DefineEnum("Elevation", TypeAttributes.Public, typeof(int));
int i = 0;
foreach (string item in _list)
{
eb.DefineLiteral(item, i);
i++;
}
return (Enum)Activator.CreateInstance(eb.CreateType());
}
}
}
2. Tried using the class but i am unable to find the "finished" enum defined above. i.e. I am not able to do the following
public static void TestDynEnum(Test.DynamicEnum.finished _finished)
{
}
I guess the post has become too long but i hope i have made it quite clear.
Why i need such a functionality?
I can very well make the method with string as a parameter. I need this so that the developer who is using the method need not have to remember the set of values, amongst which only 1 he should pass. He will directly get it through the enum which is being created dynamically.
Anyone Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
Hi Experts,
Any suggestions on this??
Regards,
Samar
|
|
|
|
|
Will generics solve the problem?
|
|
|
|
|
Any time you get some weird code from somewhere the best place to get answers when it doesn't work is to ask in the same place you got the code.
I don't really understand your goal. If your developers can't be relied upon to remember simple things then expecting them to use things like dynamic enums is probably a bad idea. Maybe if you gave an example of how it would be used we could give you an alternative. If the enum isn't built until runtime I don't see how it can give any advantage to someone at coding time.
|
|
|
|
|
Good day one and all,
I've been given a little task to create a petrol station app. The app allows for multiple "pumps" with the option of adding more petrol/gas pumps where required. Currently my app displays only one pump at a time and you change between pumps with a combo box.
Obviously in the real world you can have multiple pumps all running concurrently, so I wanted to duplicate the same form everytime a new pump class was created/instantiated.
Does anyone have a pointer on the simplest way for me to do this? A pointer to some code to look at would be ideal as I'm no coding guru at the moment.
Thanks all,
Mike.
|
|
|
|
|
Have you tried:
MyPumpForm newPump = new MyPumpForm();
newPump.Show();
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Cheers matey, that's getting me somewhere. I didn't think it would be quite that simple...
|
|
|
|
|
A problem with this is that if I close the first form that opens, it closes all subsequent ones.
|
|
|
|
|
I assume you mean "When I close the main form, all the other forms close."
Well yes. When you close the main form, the program terminates. This closes all the other forms. Look at the Main method in program.cs
If you have a pump form as your main form, then when that is closed, your app terminates.
Best solution: Don't make the pump form your main form. Have a fuel station form which opens all the pump forms. When you close the fuel station form, the app terminates.
Other solutions are rather more complex.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
I see the Force is with you today.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Use UserControls and TabPages instead of multiple forms?
|
|
|
|
|
Hi,
I want to fill the 2nd combobox with values dependent on the value from the first combobox
In reallife: The first combo contains car brands, the second a list of types. I want that when I select Ford I only get the types from Ford
private void GetVtgMerken()
{
txtBrand.DataSource = _Brand.GetVtgBrand();
txtBran.DisplayMember = "Brand_Name";
txtBran.ValueMember = "Brand_ID";
}
private void GetVtgBrandTypes(int ID)
{
txtType.DataSource = _Brandtype.GetVtgBrandTypes(ID);
txtType.DisplayMember = "type_Naam";
txtType.ValueMember = "MT_Id";
}
private void txtBrand_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = txtBrand.SelectedValue.ToString();
int ID = Convert.ToInt32(txtBrand.SelectedValue.ToString());
int ID = Int32.Parse(txtBrand.SelectedValue.ToString());
GetVtgMerkTypes(ID);
}
When I use Convert.toInt32 or int32.parse I always get the error like below.
System.FormatException: Input string was not in a correct format.
Textbox1.text displays the value correct (ex. 3)
Is there someone who can help ?
|
|
|
|
|
What's the value of txtBrand.SelectedValue.ToString() ? Check if it is really a number (meaning digits only) if it contains letters, you'll need to perform additional formatting or use another container then int for ID.
V.
|
|
|
|
|
When I do:
textBox1.text = txtBrand.SelectedValue.ToString()
the textbox shows the value "3".
An integer I think
But when I convert the textbox to an variable the debugger complains.
Kan een object van het type System.Int32 niet converteren naar het type System.Data.DataRowView.
After a long search i fixt it like this:
private void txtBrand_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtBrand.SelectedValue is DataRowView)
{
string BrandID = Convert.ToInt32(((DataRowView)txtBrand.SelectedValue)["Brand_Id"]).ToString();
int ID = Convert.ToInt32(BrandID);
GetVtgMerkTypes(ID);
}
else
{
int ID = Convert.ToInt32(txtBrand.SelectedValue.ToString());
GetVtgMerkTypes(ID);
}
}
... this works
|
|
|
|
|
conversion methods will throw a FormatException when the input string isn't in the right format, which includes the case where the input is empty. e.g. you may get that while your Form gets loaded. It is often solved easily by including a non-zero-length test in your code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Luc,
I think you are right !!!
I fixt it with the code below:
private void txtBrand_SelectedIndexChanged(object sender, EventArgs e)
{
if (txtBrand.SelectedValue is DataRowView)
{
string BrandID = Convert.ToInt32(((DataRowView)txtBrand.SelectedValue)["Brand_Id"]).ToString();
int ID = Convert.ToInt32(BrandID);
GetVtgBrandTypes(ID);
}
else
{
int ID = Convert.ToInt32(txtBrand.SelectedValue.ToString());
GetVtgBrandTypes(ID);
}
}
maybe not nice but it works
|
|
|
|