|
Looks okay in my opinion.
I would just exchange
if (drive.Name.StartsWith("C") && ignoreC == true)
with
if (ignoreC == true && drive.Name.StartsWith("C"))
This way StartsWith will only be executed when ignoreC is set to true. This is logically a bit more precise, but shouldn't make any difference in performance (unless your program runs on a pentium 80 )
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
That makes a stack of sense, thanks for that Greeeg. Glad it makes sense too, I was trying all sorts of different things in order to achieve this simplicity yesterday, nothing beats 'no code' to get 'nothing' done tho eh!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi All,
I have a datatable with some data :
ActivityNr ActivityStartTime ActivityDuration
001 20:30 00:30
002 20:30 00:40
003 20:40 00:30
004 20:50 00:30
005 20:55 00:30
As you can see, Activity 001 and 002 have the same StartTime(20:30), bud activity 002 has a longer Duration(40 minutes) then Activity 001(30 minutes).
Now i have to check all activities StartTimes and when they have the same StartTime(like 001 and 002), then i have to check the 'ActivtityDuration' of those Activities and delete the Activity with shorter duration from the datatable.
Assuming the datatable above, the end resulat most be:
ActivityNr ActivityStartTime ActivityDuration
002 20:30 00:40
003 20:40 00:30
004 20:50 00:30
005 20:55 00:30
001 is deleted because it had the same starttime as 002, bud a shorter duration.
Can anyone help me with this issue with some code ?
Thanx.
|
|
|
|
|
Pankach Udhas,
You need to create some DateTime objects and do some checks on them
Note: Its a better idea to use TryParse instead of Parse, i just used Parse because its faster to type out.
eg:
DateTime actOne = DateTime.Parse(actTwoDateTimeFromDataTable);
DateTime actTwo = DateTime.Parse(actTwoDateTimeFromDataTable);
if (actOne == actTwo )
{
DateTime actOneDur = DateTime.Parse(actOneDurationFromDataTable);
DateTime actTwoDur = DateTime.Parse(actTwoDurationFromDataTable);
if (actOneDur > actTwoDur)
{
}
else
{
}
}
Does that help?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I want to build a small utility using c# where I have to construct a hash table from any given object's properties . Say for example if a class is something like this
namespace my.project
{
using System.Runtime.Serialization;
using System.Collections.Generic;
[Serializable]
public class A: MySuper
{
public A()
{
}
private int _id;
private string _name;
private B _b;
public int ID
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public B B
{
get { return _b; }
set { _b = value; }
}
............
Now the hashtable should be like
Key Value
-- -------
id 12
name Robert
ABid 11
BC[0]id 12 //in case b has a list of c and c has a property id
BC[1]id 14
..........
...........
I was able to construct the hash map using reflection for any simple objects like A having only name and id. But in real word A might have B and B might have a List of C. So I guess I have get the property value using recursion and reflection.
Can any one suggest a better way to crate the above hash table maybe using serialization.
|
|
|
|
|
Serialization also uses Reflection internally to get the property information of a class, so you can just go the Reflection+Recursion route and everything will be fine.
This way you also don't have the limitations[^] of the standard .NET serialization classes.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The problem I am having with reflection and recursion is I only need the string or primitive type's value. Now if its a B type object or a Collections.Generic.List then the the process gets really complicated.
I am right now trying to use
if(type is System.String) // not working
,,,,,,,,,,,,,,,,
else if(type is Userdefineobject) //how to get User define object?
So basically I need to differentiate betten the ones which are string, int (isPrimitive works but how can find which one are sting or list?)etc and the ones that are user define objects(B or C type in runtime) so that I can do some recursion.
|
|
|
|
|
hi again friends,
how can i change my image opacity?
|
|
|
|
|
One way would be to change the pixel format of the image to ARGB and then save it as PNG or TIFF file, like that:
public static Image SetImgOpacity(Image imgPic, float imgOpac)
{
Bitmap bmpPic = new Bitmap(imgPic.Width, imgPic.Height);
Graphics gfxPic = Graphics.FromImage(bmpPic);
ColorMatrix cmxPic = new ColorMatrix();
cmxPic.Matrix33 = imgOpac;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
gfxPic.DrawImage(imgPic, new Rectangle(0, 0, bmpPic.Width, bmpPic.Height), 0, 0, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, iaPic);
gfxPic.Dispose();
return bmpPic;
}
using (Image img = Image.FromFile(filename))
{
Image img2 = ((Bitmap)img).Clone(new Rectangle(0, 0, img.Width, img.Height), PixelFormat.Format32bppArgb);
img2 = SetImgOpacity(img2, 0.5f);
img2.Save(filename2, ImageFormat.Png);
img2.Dispose();
}
I got the SetImgOpacity method from here[^]. I just tested this code and it works fine.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
you're really great, merci
|
|
|
|
|
What I just tried out which works, you can also convert the image to grayscale with the ColorMatrix class used above, just set the matrix to
cmxPic.Matrix00 = 0.299f;
cmxPic.Matrix01 = 0.299f;
cmxPic.Matrix02 = 0.299f;
cmxPic.Matrix10 = 0.587f;
cmxPic.Matrix11 = 0.587f;
cmxPic.Matrix12 = 0.587f;
cmxPic.Matrix20 = 0.114f;
cmxPic.Matrix21 = 0.114f;
cmxPic.Matrix22 = 0.114f;
This will produce a grayscale image with a different approach as presented in the aricles.
Hope this helps
modified 12-Sep-18 21:01pm.
|
|
|
|
|
hi again friends,
i have an image and i want to make it white and black. how can i do that?
thanks
|
|
|
|
|
Sajjad Izadi wrote: i have an image and i want to make it white and black. how can i do that?
Do you mean programmatically?
If not, then this is the wrong forum, but you could use Photoshop or similiar to do that.
Kristian Sixhoej
"Failure is not an option" - Gene Kranz
|
|
|
|
|
Yes , what is the probloem?
|
|
|
|
|
Here you go[^]
If you want to get in touch with image processing, then I also recommend the parts 2-5 from the series, they're really interesting and helpful.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
your suggested project was great but what is the parts 2-5 from the series? please give some more explanation about them
|
|
|
|
|
|
that was again great, thank you
|
|
|
|
|
hi friends,
How can i descover that what is the current screen resolution (1027*768 or 1152*864 or etc)?
|
|
|
|
|
Screens.PrimaryScreen, from memory
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
that worked, thanks a lot
|
|
|
|
|
im using the following code snippet to find mispelled words and highlight them...
PhoenixText.Forms.MdiWindow win = (PhoenixText.Forms.MdiWindow)this.ActiveMdiChild;
Char[] characters = win.TextBox.Text.ToCharArray();
bool stop = false;
foreach (string word in win.KeyWords)
{
for (int p = 0; p <= win.TextBox.Text.Length;p = p)
{
int endIndex = p;
foreach (char lett in characters)
{
if (stop == false)
{
if (lett.ToString() != " ")
{
endIndex++;
}
else
{
stop = true;
}
}
}
win.TextBox.Select(p, endIndex);
win.TextBox.SelectionColor = Color.Red;
win.TextBox.ForeColor = Color.Black;
p = endIndex + 1;
}
}
The problems are...
1. It wont just highlight 1 word
2. The RichTextBox's forecolor gets changed to red so that when you type oiut more text, its all red.
If anyone know how to fix these problems, thanks in advance.
|
|
|
|
|
use the string's split method to break your text into words, instead of chars.
I'm not sure how to fix issue b.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Fixed it!!!
SpellCheck checker = new SpellCheck();
PhoenixText.Forms.MdiWindow win = (PhoenixText.Forms.MdiWindow)this.ActiveMdiChild;
Char[] characters = win.TextBox.Text.ToCharArray();
foreach (string word in win.KeyWords)
{
int firstIndex = win.TextBox.Text.IndexOf(word);
int lastindex = word.Length;
if (checker.CheckSpelling(word) == false)
{
win.TextBox.Select(firstIndex, lastindex);
win.TextBox.SelectionFont = new Font(win.TextBox.Font, FontStyle.Underline);
win.TextBox.DeselectAll();
win.TextBox.Refresh();
}
}
|
|
|
|