|
i have form MDI parent and other forms child for it
when i open first form inside the MDI parent i use the following code:
Items.AddItem additem = new Items.AddItem();
additem.MdiParent = this;
additem.Show();
untill now there is no problem but when i want to open another form by clicking any button inside the child form, i want to be child for the MDI parent but nothing happen.
i use the following code:
frm_Main main = new frm_Main();
Items.AddItemUnits itemunit = new AddItemUnits();
itemunit.MdiParent = main;
itemunit.Show();
i want to open the itemunit inside the main "which is MDI paren"
please reply me
Sayed M. Ali
Solution Developer
|
|
|
|
|
You are recreating your Mdi parent in frm_Main main = new frm_Main(); Why not remove this line, and replace itemunit.MdiParent = main; with itemunit.MdiParent = this.MdiParent;
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I'll preface this by saying that I'm a Webservice novice. I get the concept, but I know next to nothing about the details. It's something I need to remedy, especially with SOA/WCF/etc. That being said...
I have two Web Site Projects. One is exposed to the other as different webservices. I have a class in the service project that I'd like to consume in the other project. This class contains properties and methods. I've noticed a few things:
- The class won't be exposed in the wsdl unless it's used by the asmx.cs file. Simply having the class in the same assembly doesn't mean anything.Is that correct?
- When I use the class as a return type of one of the service's web methods, it's defined in the wsdl as a compex type bt with no fields or methods. Is this because the service will only expose the fields of the class (i.e. not the properties or the methods)?
- Assuming the above to be true, is there any way for my consumer project to consume this class and use its methods without exposing the methods in the web service? Or am i going about this the wrng way entirely?
Thanks for your help.
|
|
|
|
|
Hi,
a mysterious Exception has occurred in one of my applications, thrown while doing or preparing a web request using a WebProxy:
"System.NotSupportedException: The ServicePointManager does not support proxies of web-proxy scheme."
I did not explicitely use a "ServicePointManager". Unfortunately I cannot backtrack where this Exception was thrown exactly.
Google did not return a usable information about this error message.
What does this message mean? Has anybody an idea?
Thanks in advance,
Alex
|
|
|
|
|
HI,
I'm building COM obejct in C++ and using it in C# and I can't figure out which type in C++ coresponds to bool type in C#. If I use bool in C++ , I allways get "expecting a type specification near "bool" " error. I tried boolean or BOOL , but any of them corresponds to bool in C# (after COM object is wrapped in .NET VS)
Do you have anty idea how what to use?
|
|
|
|
|
Hi, we're a couple of students on our internship, and we're kinda stuck in the project we're doing. I'll first try to explain what it is we are expected to make.
You have to imagine a white empty 2D paper which is virtually unlimited in size. An admin can place a question on this paper, users can then reply on the active question. The admin can also zoom in and zoom out and drag the paper around and post new questions. So we have to work with an environment that contains a fair amount of questions linked to answers. Every question can be differently scaled, so this means that you have to zoom in more on some questions than others.
Basic functionality would have to be panning the paper, by that I mean hold mouse down and dragging it to another position, thus moving all objects on the paper in that direction.
We've tried this with the following code, however the performance was really bad.
void Window_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)<br />
{<br />
if (mbMouseDown)<br />
{<br />
Point bNew = e.GetPosition(Window);<br />
foreach (UIElement oObject in LayoutRoot.Children)<br />
{<br />
Canvas.SetTop(oObject, bNew.X - mpBegin.X);<br />
Canvas.SetLeft(oObject, bNew.Y - mpBegin.Y);<br />
}<br />
}<br />
mbMouseDown = false;<br />
}<br />
<br />
void LayoutRoot_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)<br />
{<br />
if (mbMouseDown)<br />
{<br />
Point bNew = e.GetPosition(Window);<br />
foreach (UIElement oObject in LayoutRoot.Children)<br />
{<br />
Canvas.SetTop(oObject, bNew.X - mpBegin.X);<br />
Canvas.SetLeft(oObject, bNew.Y - mpBegin.Y);<br />
}<br />
}<br />
}<br />
<br />
void LayoutRoot_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)<br />
{<br />
mbMouseDown = true;<br />
mpBegin = e.GetPosition(Window);<br />
}
With the zooming we tried the scaling functionality of wpf.
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)<br />
<br />
{<br />
<br />
if (e.Delta > 0)<br />
<br />
{<br />
<br />
mpScaleSize = new Point((mpScaleSize.X - 0.05), (mpScaleSize.Y - 0.05));<br />
<br />
grdCanvas.LayoutTransform = new ScaleTransform(mpScaleSize.X, mpScaleSize.Y);<br />
<br />
zoomX.Content = mpScaleSize.X.ToString();<br />
<br />
zoomY.Content = mpScaleSize.Y.ToString();<br />
<br />
}<br />
<br />
else<br />
<br />
{<br />
<br />
mpScaleSize = new Point((mpScaleSize.X + 0.05), (mpScaleSize.Y + 0.05));<br />
<br />
grdCanvas.LayoutTransform = new ScaleTransform(mpScaleSize.X, mpScaleSize.Y);<br />
<br />
zoomX.Content = mpScaleSize.X.ToString();<br />
<br />
zoomY.Content = mpScaleSize.Y.ToString();<br />
<br />
}<br />
<br />
}
This again wasn't going smoothly.
(My laptop is a IBM Thinkpad r50p, 1,7Ghrz Centrino, 1gig RAM, maybe it's just not fast enough?)
Anyway , I've posted this same question on the msdn forums. One person with little experience with the subject suggested me that I should try to work with visualBrushes and use it as some kind of view. I've been playing around with the VisualBrushes for a while now.
I've managed to get controls from code onto the VisualBrush(which is on a rectangle in the center of my app), however working with VisualBrush as some kind of view isn't working for me.What I "discovered"is that working with the viewbox property of the visualbrush might be the solution, but I can't seem to get it to work.
To my understanding the viewbox is a rectangle with it's x & y as panning values, and it's with & height as crop/stretch values (zoom).
Anyone with some experience in the area, I would really appreciate the help.
Thanks,
Tobias
|
|
|
|
|
I always meet the situation in my code. For example when filling array while parsing a text file or reading Sql query result.
I used two solutions to this:
1. at first I fill ArrayList, then copy items to the array with help of CopyTo method of ArrayList
<code>
ArrayList arr = new ArrayList();
while(reader.Read())
{
arr.Add(reader.GetString(0));
}
string[] strs = new string[arr.Count];
arr.CopyTo(strs);
... do sth
return strs;
</code>
2. create array of maximum expexcted length and then copy items to new array when first array is filled and the length is known
<code>
string[] strs = null;
using(string[] tmpArray = new string[MAX_POSSIBLE_LENGTH])
{
int i = 0;
while(reader.Read())
{
tmp[i] = reader.GetString(0);
i ++;
}
strs = new string[i];
Array.Copy(tmpArray, strs, i);
}
... do something
return strs;
</code>
Does somebody know the better solution? If there is not one which of the above is better?
Evgeny Pokhilko
C# .NET monomaniac
|
|
|
|
|
The first is obviously better. There's no other way, an ArrayList will allow you to change the size, an Array will not. I assume you're not using .NET 2.0, if you are, don't use arraylist.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi there,
We're having a small test here at work. Read in a text file and convert half the text to uppercase as quickly as possible ("aabb" => "aAbB", so not "AAbb")
So I read in the text file and do a for with i+=2 instead of i++ and setting a Stringgbuilder. after the text is done I put text into the text box. Then I use ngen to boost speed a bit (compiler is set to optimized etc.) I also tried to use SuspenLayout and ResumeLayout, but that didn't gain me a lot.
Any other tricks I can use to boost this up? (maybe I forgot to set some compiler options or I have to do it in another way?
here's my code:
System.IO.StreamReader reader = new System.IO.StreamReader(openfiledlg.FileName);
text = new StringBuilder(reader.ReadToEnd());
reader.Close();
pb_conversion.Maximum = text.Length;
starttime = DateTime.Now;
for(int i = 1; i < text.Length; i+=2){
text[i] = text[i].ToString().ToUpper()[0];
pb_conversion.Value = i;
}
txtbox_result.Text = text.ToString();
difference = DateTime.Now - starttime;
lbl_result.Text = "Done in: " + difference.TotalMilliseconds + " milliseconds.";
lbl_result.Visible = true;
I'm curious what else I could do...
thanks.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
You could go through the text as a char array and just subtract 32 from each other char to get uppercase.
Might be a little faster.
|
|
|
|
|
I reckon the ToString is probably expensive. Just deal with chars, instead. You can use Char.IsLower to find out if a char is a lower case letter, or just use Char.ToUpper to convert it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
thanks for the reply. I'm around 81 seconds with a 20 Mb file. (84 first)
|
|
|
|
|
I had a play round with this, and got a 21 MB file to process in about 10 seconds. This code isn't perfect, but it is a decent basis to carry on with:
public void ReadFile()
{
if (openfiledialog.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader reader = new System.IO.StreamReader(openfiledialog.FileName);
StringBuilder text1 = new StringBuilder(reader.ReadToEnd());
reader.Close();
pb_conversion.Maximum = text1.Length;
DateTime starttime = DateTime.Now;
int innercount = 0;
for(int i = 1; i < text1.Length; i+=2)
{
text1[i] = text1[i].ToString().ToUpper()[0];
if (++innercount == 1000)
{
innercount = 0;
pb_conversion.Value = i;
}
}
txtbox_result.Text = text1.ToString();
TimeSpan difference = DateTime.Now - starttime;
MessageBox.Show(difference.ToString());
}
} One of the key areas is that you no longer attempt to update the progress bar every iteration. This is just wasteful and should be avoided - which is why I update every 1000 iterations.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
dude,
I couldn't believe my eyes when I saw the difference
11 seconds !
thanks man.
|
|
|
|
|
Glad to be of service.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Wouldn't using a char[] be faster than using a StringBuilder?
<br />
char[] c = sr.ReadToEnd().ToCharArray();<br />
<br />
for (int i = 0; i < c.Length; i+=2)<br />
{<br />
c[i] = (char)((int)c[i] - 32);<br />
}<br />
|
|
|
|
|
It would, but you need to enclose the c[i] test with an if (char.IsLetter(c[i])... so that you don't end up converting none alphabetic characters.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello,
I want to copy a string into a byte[] array.
string has a method ToCharArray that returns a char[] but that`s just not good enough, since a char is 2 bytes.
Is there a quick and easy way to accomplish this? In unmanaged C++ I could just do a memcpy or memmove into a designated BYTE array, is there something similar I can use in C#?
Thanks for your feedback,
Davy
|
|
|
|
|
byte[] mybyte = Encoding.ASCII.GetBytes("Hello World");
|
|
|
|
|
byte[] bytes = System.Text.Encoding.ASCII.GetBytes("MyString");
where ASCII can be replaced with other available encodings.
|
|
|
|
|
System.Text.Encoding.
A byte sequence means nothing without the information on how to map the byte sequence to characters. This is what the Encoding classes do.
|
|
|
|
|
Thanks all
That`s what I was looking for!
|
|
|
|
|
hi everyone,
I am working in a C# 2.0 Windows Aplication and it had a menu strip. I made a function to hide some of its MenuItems under certain circumstances. the Function was some thing like this
public static void Hide_MenuItems(MenuStrip menustrip)
{
try{
menustrip.Items["productsMenuStipItem"].Visible = false;
menustrip.Items["productreportsMenuStipItem"].Visible = false;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Now that code is giving a Null reference exception on productreportsMenuStipItem which is an item that come under the MenuItem like this Products--->Product Reports.
So far I'm not able to understand why this is happening coz when I write this
productreportsMenuStipItem.Visible = false;
in the form that has that menuStrip it working perfectly alright but when I try to do that in this function it gives out a nullReferenceException. It seems as if the only Menuitems tranfered are the ones that are at level zero. like that productsMenuStripItem.
Can u plz give me a clue so that I can hide the menuStipItems with the help of this function? or atleast explain why this is happening?
thanks in advance
Rocky
|
|
|
|
|
I am guessing this has to do with nested menu items. It seems like you are hiding the parent item so the children items aren't there. I am not sure why you are doing it this way. You can access the object directly.
this:
productreportsMenuStipItem.Visible = false;
is not the same as this:
menustrip.Items["productreportsMenuStipItem"].Visible = false;
One you are marking the menu item itself as not visible. Then other you are using the Menustrip to access the menuitem. I would suggest always accessing the menustripitem directly and I think you won't have any problems.
Hope that helps.
Ben
|
|
|
|
|
Hello,
I have a long treeView, how can I scroll to the top of the control, without selecting anything?
Please help.
|
|
|
|