|
If this is the same App we talked about yesterday, the list you created to show which forms need to be closed would also double up as a list of open forms wouldn't it? If it needs to be closed at log off, it's open... If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Hello I have a simple Panel class object that has a Button and Label on it.
I use the button to display an image and the label to display info on it.
It is used as a "Media Selection Tool"
The problem that I am having is when I resize the object there are cases when I will modify the object's size again.
When this is done, the code will recall the resize event again and again till its happy then exit.
Can I not prevent the resizing event till all the width and height stuff is done?
if (mode == 0)
{
this.Width = ImageButton.Width;
InfoTextBox.Visible = false;
}
For example when the above occurs, there is no infomation to be displayed therefore my object only needs to be the size of the Button to display the image.
But when "this.Width = " is executed the whole resize event gets called again.
Thank you in advance.
PS is this just sloppy code?
private void Initialize_Components()
{
this.SuspendLayout();
this.Width = 200;
this.Height = 200;
ImageButton = new Button();
InfoTextBox = new Label();
ImageButton.BackgroundImageLayout = ImageLayout.Stretch;
this.Click += new System.EventHandler(MediaIconButtonClick);
ImageButton.Click += new System.EventHandler(MediaIconButtonClick);
InfoTextBox.Click += new System.EventHandler(MediaIconButtonClick);
this.BorderStyle = BorderStyle.Fixed3D;
this.Controls.Add(ImageButton);
this.Controls.Add(InfoTextBox);
this.Resize += new System.EventHandler(this.MediaIconClass_Resize);
this.ResumeLayout(false);
this.PerformLayout();
}
public MediaIcon()
{
Initialize_Components();
}
private void MediaIconClass_Resize(object sender, EventArgs e)
{
this.SuspendLayout();
InfoTextBox.Height = this.Height;
ImageButton.Height = this.Height;
if (ImageHeight != 0)
{
ImageButton.Width = ImageButton.Height * ImageWidth / ImageHeight;
InfoTextBox.Left = ImageButton.Right;
}
else
{
ImageButton.Width = this.Width / 2;
InfoTextBox.Left = ImageButton.Right;
}
if (mode == 0)
{
this.Width = ImageButton.Width;
InfoTextBox.Visible = false;
}
else
{
InfoTextBox.Visible = true;
}
this.ResumeLayout(false);
this.PerformLayout();
}
|
|
|
|
|
You could do one or more of the following:
1) Check to see if it is already that width, and if so don't change it.
2) Remove the resize event handler at the top of a series of changes, and reinstate it just before the last one.
3) Add a bool to say "Resizing" and check it at the start of your event handler.If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
Sorry for my poor English.
My Question is: How to get which group was matched after a regex.match with grouped pattern string?
for instance:
string strPattern = "\Wo*e\W|\Wt*o\W|three|four";
string strTextToSearch = "there are two apples on the table";
Regex r = new Regex(strPattern);
Match m = r.Match(strTextToSearch);
if (m.Success)
{
//how can i know it is keyword "\Wt*o\W" was matched but not the others?
}
|
|
|
|
|
newproger wrote:
Nightmare with Regular Expression
YES you're right(not left) RegExp==NIGHTMARE
I'm sorry I just feel like joking. I can't help it.
|
|
|
|
|
Groups are automatically named according to their occurance order, but you can also name them yourself (this is called "named groups"). For example, the following regular expression has three named groups:
The (?<ANIMAL>cat|dog|penguin|langolier) (?<TRANSPORT>walked|waddled|flew) down the (?<PATH>street|yellow brick road|slope)\.
|
|
|
|
|
Thanks for reply.
But in my program, the pattern string is generated at runtime(keywords inputed by user), I can't know how many keywords in design time, so I can't set fixed group name in codes.
|
|
|
|
|
newproger wrote: Regex r = new Regex(strPattern);
Match m = r.Match(strTextToSearch);
if (m.Success)
{
//how can i know it is keyword "\Wt*o\W" was matched but not the others?
}
maube something like this:
m.Groups[1].Value
m.Groups[1].Index
|
|
|
|
|
i notice that in c# or c++, we normally indicate the size of an array.
string[] strArray = new string[5];
strArray[0] = "Ronnie";
strArray[1] = "Jack";
strArray[2] = "Lori";
strArray[3] = "Max";
strArray[4] = "Tricky";
Another way is like this:
string[] strArray = new string[] {"Ronnie", "Jack", "Lori", "Max", "Tricky"};
Both have fixed size. is there a way to create an array which can store unlimited amount of data?
I know of ArrayList but it is not available in compact framework.
|
|
|
|
|
What about List?
It has all the functionality of array/arrayList.
|
|
|
|
|
okay my bad. arraylist is available in compact framework.
however, im gonna try your suggestion instead. List looks like a better choice =)
|
|
|
|
|
Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.
|
|
|
|
|
|
There is something called Redim which used to resize the array at later stage, or the best you can do is go for arraylist
|
|
|
|
|
C# doesn't have a ReDim method like VB.NET does.
And, in VB.NET ReDim does NOT resize an array. Behind the scenes it has to do the exact same thing you'd do manually. It creates a new array of the required size, copies the data to it, then destroys the original array.
|
|
|
|
|
Actually, all .NET languages have access to the static "System.Array.Resize" method (since .NET Framework 2, I believe) - but as you said, there's no magic - it just does the same copying that VB's ReDim does. David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Yeah, I was saying that C# didn't have an equiv keyword to VB.NET's ReDim.
|
|
|
|
|
Just got back into writing code after 10 years. This is a infix to postfix converter. Can someone please critique this...
thanks
using System;
using System.Collections;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Infix2Postfix
{
public class Program
{
static void Main(string[] args)
{
#region variable declarations
String stringInfix = "a+b/c-d";
StringBuilder SbPostfix = new StringBuilder();
Stack<char> stackGeneral = new Stack<char>();
Stack<char> stackOperator = new Stack<char>();
char[] tempArray = stringInfix.ToCharArray();
Array.Reverse(tempArray);
Regex regexAlphaNum = new Regex("[a-zA-Z0-9]");
char temp;
#endregion
#region logic
foreach (char ch in tempArray)
stackGeneral.Push(ch);
foreach (char ch in stackGeneral)
{
if (regexAlphaNum.IsMatch(Convert.ToString(ch)))
SbPostfix.Append(ch);
else if (stackOperator.Count == 0)
stackOperator.Push(ch);
else if (stackOperator.Count != 0)
switch (ch)
{
case '+':
temp = stackOperator.Peek();
if (temp == '*' || temp == '/')
{
while (stackOperator.Count > 0)
SbPostfix.Append(stackOperator.Pop());
stackOperator.Push(ch);
}
else
stackOperator.Push(ch);
break;
case '-':
temp = stackOperator.Peek();
if (temp == '*' || temp == '/')
{
while (stackOperator.Count > 0)
SbPostfix.Append(stackOperator.Pop());
stackOperator.Push(ch);
}
else
stackOperator.Push(ch);
break;
case '*':
temp = stackOperator.Peek();
if (temp == '*' || temp == '/')
{
while (stackOperator.Count > 0)
SbPostfix.Append(stackOperator.Pop());
stackOperator.Push(ch);
}
else
stackOperator.Push(ch);
break;
case '/':
temp = stackOperator.Peek();
if (temp == '*' || temp == '/')
{
while (stackOperator.Count > 0)
SbPostfix.Append(stackOperator.Pop());
stackOperator.Push(ch);
}
else
stackOperator.Push(ch);
break;
}
}
while (stackOperator.Count > 0)
SbPostfix.Append(stackOperator.Pop());
#endregion
#region output to screen
Console.WriteLine("Equation in infix notation: {0}", stringInfix);
Console.Write("Equation in postfix/RPN notation: {0}", SbPostfix);
Console.ReadKey();
#endregion
}
}
}
|
|
|
|
|
I don't think you need tempArray.
How does it handle malformed input?
Here's[^] my infix-to-postfix code; there are others on here.
|
|
|
|
|
It only handles inputs in a*b-c/d format. The code is very basic, written in an non elegant way. I will look at your code, it might give me some insights.
|
|
|
|
|
Here I am criticizing it
It's too long and too late at night for me . Now it's joke time :cool
|
|
|
|
|
|
and i.push()
|
|
|
|
|
|
I would fire you on the spot for putting regions in a method and not maintaining consistent capitalization of variables.
|
|
|
|