|
You could implement the IClonable interface in your PictureBox class. This interface is used to create a copy of an object, but you would still have to write the attribute copying code in there.
|
|
|
|
|
How can I pass to Interlocked.Exchange(...) an object of my own type?
In the code below both DoNothing and Interlocked.Exchange generate a compiler error.
using System;
using System.Threading;
class MyObject
{
}
class ReferenceTry
{
[STAThread]
static void Main(string[] args)
{
MyObject o = new MyObject();
MyObject oo;
DoNothing(ref o);
oo = (MyObject) Interlocked.Exchange(ref o, null);
// do something with oo
}
static void DoNothing(ref object o)
{
}
}
|
|
|
|
|
First, you never said what the error was.
Second, Interlocked.Exchange returns a value and takes two parameters, neither of which can be null . You're code isn't passing an Object into the function either.
someType2 = (SomeType)Interlocked.Exchange(ref someType1, (object)someType2);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
So, the reference parameters do not work with subclasses?
Then Interlocked.Exchange(ref object, object) can't be used for anything?
Because if I make a variable
object o2 = (object) o;
and call
oo = (MyObject) Interlocked.Exchange(ref o2, null);
o = (MyObject) o2;
then I lost the atomicity (another thread can set o between Interlocked.Exchange and o = (MyObject) o2; ).
And if I declare o as object I must cast it every time I wish to use MyObject's members.
|
|
|
|
|
The first parameter can be passed as any type of object, but the second parameter MUST be passed as Object.
Interlocked.Exchange( someType1, CType(someType2, Object))
If you can convert null to an Object, you're in business.
Interlocked.Exchange Method (Object, Object)[^] docs on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have two images that I am ANDing into 1 image. I have also tried XOR'ing the images into 1.
The resulting image has both image 1 and 2 together, image 2 is kinda off colored, sometimes dark, and image 1 is fine.
my question is, how can i get my resulting image cleaner to where it can be presentable? Cant I, after anding them into 1 image, put the areas that are the same in all black, and the newer area's to be normal color? If so, i can then run code to make the black area's transparent so that it will fit over the original image cleaner (meaning no dark shading or off colors).
I wish I could post a screen shot to what im speaking of. The example I am using is found at http://www.codersource.net/csharp_image_processing_xor.aspx[^]
Any help would be appreciated.
Steve Welborn
Software Architect
|
|
|
|
|
Swelborn wrote:
If so, i can then run code to make the black area's transparent so that it will fit over the original image cleaner (meaning no dark shading or off colors).
Sure - just add a check in the code you're using that if one pixel is black, you just copy the other one. I don't think this will work too well tho, not all black areas are background, and not all background areas are black. One has to wonder just how clear you expect each image to be if you're merging them, and what this is being used for ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've searched in the forums, in the articles and even in the MSDN, but I'm not able to understand what the filealign option for the c# compiler does.
All that I know is that reduces the filesize a bit.
Other functions?
I wonder if Microsoft has included another useless option.
Tozzi is right: Gaia is getting rid of us. Do you feel the way you hate or do you hate the way you feel?
|
|
|
|
|
|
If your project was going to be transferred to a Pocket device, you'd probably want the .EXE sections packed to 512 byte boundries to save space.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
So it's only a filesize matter. At least now I know it.
Tozzi is right: Gaia is getting rid of us. Do you feel the way you hate or do you hate the way you feel?
|
|
|
|
|
Class B includes a method "public void Save()".
Class A includes one field which type is B.
In some other class I am using reflection to gather information about class A and B:
<code>
{
Type ClassType = typeof(refl.A);
FieldInfo[] fields = ClassType.GetFields();
foreach(FieldInfo f in fields)
{
Type t = f.FieldType;
MemberInfo[] members = t.GetMembers();
foreach (MemberInfo m in members)
{
if (m.Name == "Save")
{
<big> ?????
</big>
}
}
}
}
</code>
When I find a function Save, i would like to call it. This isn`t a static method so I need to call it over some object. How to make it inside reflection?
|
|
|
|
|
|
You could do something like this.
<code>
public class B
{
public void Show()
{
System.Windows.Forms.MessageBox.Show( "B.Show called!" );
}
}
public class A
{
private B mB;
public B MemberB
{
get
{
return ( this.mB );
}
set
{
this.mB = value;
}
}
public A()
{
this.mB = new B();
}
}
public Class Tester
{
private A mA;
public void Do()
{
object lB;
lB = this.mA.GetType().GetProperty("MemberB").GetValue(this.mA, null );
lB.GetType().InvokeMember("Show",System.Reflection.BindingFlags.InvokeMethod, null, lB, new object[] { } );
}
}
</code>
I hope this helps.
<i>Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons </i>
|
|
|
|
|
Thank you both, it seems to be working
One more question - suppose that properties does not exsist.
public class A
{
int i;
void show() { ... }
}
public class B
{
A a;
}
How to (using reflection on class B) call a non-static function on member a? (like:
B b = new b();
b.a.show();
)
thank you for help
|
|
|
|
|
Hello,
In my datagrid, the TextColumn are set to:
aTextColumn.Alignment = HorizontalAlignment.Center;<br />
aTextColumn.Width = 140;<br />
aTextColumn.Format = "c";<br />
aTextColumn.FormatInfo = numberFormatInfo;
However, the first 5 rows, are appended and do not display dollar values, but they still display the dollar sign in front of all the values. Is there a way (like overriding the Paint method) of removing the dollar sign for the first 5 rows?
Thank you.
|
|
|
|
|
I have a datatable containing a date field which I have databound to a textbox on a form (the textbox is read only). Sometimes the date field is null, so in those cases I want to have the textbox (and it's associated label) disappear completely. I tried intecepting the Binding.Format event to example the value from the data source and set the visibily of the textbox control like this (tbValidTo is the textbox, lblValid is just a label):
<br />
private void tbValidTo_Format(object sender, ConvertEventArgs e)<br />
{<br />
if (e.Value == DBNull.Value)<br />
{<br />
if (tbValidTo.Visible)<br />
{<br />
tbValidTo.Visible = false;<br />
lblValid.Visible = false;<br />
}<br />
}<br />
else<br />
{<br />
if (!tbValidTo.Visible)<br />
{<br />
tbValidTo.Visible = true;<br />
lblValid.Visible = true;<br />
}<br />
DateTime dt = DateTime.Parse(e.Value.ToString());<br />
if (dt<DateTime.Now)<br />
{<br />
lblValid.ForeColor = Color.Red;<br />
}<br />
else<br />
{<br />
lblValid.ForeColor = SystemColors.WindowText;<br />
}<br />
e.Value = dt.ToString("MMMM d, yyyy");<br />
}<br />
}<br />
The problem is that this code is acting really weird. As you flick between records it sometimes fails to update the textbox and instead contains the old value. Sometimes it fails to reappear when flicking from a null date record to a record with a data. When I set a breakpoint at the begining of the event I can see that usually the event fires only once when you change records but sometimes it fires 3 times (it gets as far as setting the visibility and then suddenly refires) and other times it doesn't fire at all. Can anybody suggest what the problem here might be? I have another double field that also get's hidden and it works fine so long as the date field is disabled, otherwise it does the same thing. Other fields (that don't get hidden but do get formatted) behave just fine.
|
|
|
|
|
I have a class called tasks and right now it uses compareto to sort by duedate when it is in an arraylist, that is fine for right now, but I'm expanding to group by category. I now want to sort by category and then sort by duedate within the category sort. Is this possible? Here's my class:
<br />
public class Task: IComparable<br />
{<br />
private int _importance;<br />
public int Importance<br />
{<br />
get { return _importance; }<br />
set { _importance = value; }<br />
}<br />
<br />
private DateTime _DueDate;<br />
public DateTime DueDate<br />
{<br />
get { return _DueDate; }<br />
set { _DueDate = value; }<br />
}<br />
<br />
private string _subject;<br />
public string Subject<br />
{<br />
get { return _subject; }<br />
set { _subject = value; }<br />
}<br />
<br />
private string _entryID;<br />
public string EntryID<br />
{<br />
get { return _entryID; }<br />
set { _entryID = value; }<br />
}<br />
private string _category;<br />
public string Category<br />
{<br />
get { return _category; }<br />
set { _category = value; }<br />
}<br />
<br />
public int CompareTo(object other) <br />
{ <br />
return _DueDate.CompareTo(((Task)other)._DueDate); <br />
}<br />
<br />
}<br />
|
|
|
|
|
Try this:
public int CompareTo(object value)
{
Task compObj = (Task) value;
int result = _category.CompareTo(compObj._category);
if (result == 0)
result = _DueDate.CompareTo(compObj._DueDate);
return result;
}
www.troschuetz.de
|
|
|
|
|
my drop down boxes are not returning the correct choice when a user picks one. It still shows the old one. How can I get my code to see the new choice? In VC++ there was the UpdateData() function. Is there one similar to that in C#?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
ComboBox1.SelectedItem returns the current selection.
|
|
|
|
|
Can anyone offer any recommendations / tips for designing an 'options' dialog.
I just have a form with tabs for the the various categories, onChange events for the various form elements and I read / write my app.config file.
Seems a bit messy and ad-hoc, is there a a better way ?
|
|
|
|
|
Hello!!
I need to get the size of all images from an html page but i cant do one thing.
Whith this expression i get only images where heigth and width come in this order.
Ex:
<img src="../home/images/topo_01.gif" height="107" width="213">
<img src="../home/images/topo_01.gif" width="213" height="107">
i can make only one to work.
How do i do this?
r = new Regex("<\\s*img.*height=\"(?<heigth>.*?)\".*width=\"(?<width>.*?)\".*>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
thanks!!
Bruno Conde
pharaoh
|
|
|
|
|
r = new Regex(@"<img.+(height="?(?<height>[^"]+)"?\s+width="?(?<width>[^"]+)|width="?(?<width>[^"]+)"?\s+height="?(?<height>[^"]+)).*>")
This works fine for me
Remember you can put an "@"-sign in front of your string declaration, so you don't need to escape certain characters. This comes in very handy with regular expressions.
regards
-- modified 12-Sep-18 21:01pm.
|
|
|
|
|
I need a Cyclic Visual for a form I am developing. A cyclic is the control in a helicopter that the pilot usings to steer the aircraft. What I need is an overhead view of the position of the cylic. I.e. a circle with maybe a dot or something indicating its position. Any help would be much appreciated. Thanks
D
|
|
|
|