|
BREdwards wrote: Lookup? As in a select case statement?
Select...Case . Array lookup. Hashtable lookup. These are all viable options.
BREdwards wrote: I suppose my next dilemma is trying to figure out what goes into that if statement, I believe my best bet is some sort of select case statement, though the last time I tried that resulted in error. And I'm still trying to figure out what to about the IsNumber(), or rather what I need to put between those parenthesis.
Keep trying and you'll get there. Good luck .
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
First off, I'd say this should be in the KeyPress event handler.
The replacements can be done with a switch or Dictionary.
I expect the quickest way to do the reversal is to set the insertion point back to the start of the text with SelectionStart=0 after each character is added, but the user could move the insertion point so handle Click as well.
No, wait, set RightToLeft=true
|
|
|
|
|
Thanks so far. The string reversal part is all taken care of, my problem is having to dynamically replace all number with their word equivalents, here's what I have so far:
<br />
public string Reverse(string x)<br />
{<br />
int i;<br />
char[] charArray = new char[x.Length];<br />
int len = x.Length - 1;<br />
for ( i = 0; i <= len; i++)<br />
if(char.IsNumber(x,i))<br />
{<br />
switch(i)<br />
{<br />
case'0':<br />
x.Replace("0","zero");<br />
break;<br />
}<br />
}<br />
charArray[i] = x[len-i];<br />
return new string(charArray);<br />
}<br />
I have something of an idea of what needs to be done, problem is, I can't seem to use that if statement without breaking the program. I keep getting an "index was outside the bounds of the array error" for both letters and numbers. I simply don't understand what I'm doing wrong, never had to do something like this before.
|
|
|
|
|
Try this for the reversal (not taken care of if you have an error message ):
public string Reverse(string x)
{
char[] charArray = x.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
|
|
|
|
|
This does what you ask using a Hashtable...
public string Reverse(string x)
{
char[] charArray = x.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
private static class NumericStringRepresentations
{
private static Hashtable _PairsTable = new Hashtable(9);
public static Hashtable PairsTable
{
get { return _PairsTable; }
}
static NumericStringRepresentations()
{
_PairsTable.Add("0", "zero");
_PairsTable.Add("1", "one");
_PairsTable.Add("2", "two");
_PairsTable.Add("3", "three");
_PairsTable.Add("4", "four");
_PairsTable.Add("5", "five");
_PairsTable.Add("6", "six");
_PairsTable.Add("7", "seven");
_PairsTable.Add("8", "eight");
_PairsTable.Add("9", "nine");
}
}
public string NumbersToStrings(string x)
{
string returnString = "";
if (!(x.Length == 0))
{
for (int i = 0; i < x.Length; i++)
{
string thisCharacter = x.Substring(i, 1);
int returnedInt;
if (int.TryParse(thisCharacter, out returnedInt))
{
returnString += NumericStringRepresentations.PairsTable[thisCharacter];
}
else
{
returnString += thisCharacter;
}
}
}
return returnString;
}
|
|
|
|
|
Marvelous! I was planning to use an array, but this works as well. Thank you, I'll be sure to save this so I can study later. However, when compiled, it delivers an error saying: "The Modifier 'static' is not valid for this term."
After a bit of research, I found that my version of VS is too old to have static as a modifier for the class, as I am using 2003 still.
Anyhoo, thanks for eveything.
|
|
|
|
|
I'd like to create a button that isn't the standard rectangular shape.
Haven't found anything in the articles, the forums or on the net on how to do it.
So far the only solution I can come up with is to use a PictureBox, handle the mouse events, etc...
Any suggestions or code snippets would be great.
thanks,
Mike
|
|
|
|
|
This code came from here[^]. It needs a little work in the OnPaint as it doesn't display the text but it might help get you started...?
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CustomButtons
{
public class MyButton : Button
{
protected override void OnPaint(PaintEventArgs e)
{
Rectangle rect = new Rectangle(new Point(0, 0),
new Size(this.Width, this.Height));
System.Drawing.Drawing2D.GraphicsPath myPath = new
System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
myPath.AddEllipse(rect);
Region myRegion = new Region(myPath);
this.Region = myRegion;
using (System.Drawing.Drawing2D.LinearGradientBrush brush =
new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.CornflowerBlue, Color.White, 45))
{
e.Graphics.FillEllipse(brush, 0, 0, this.Width, this.Height);
}
}
}
}
|
|
|
|
|
One little additional hint: I don't think that creating a new Region every time the button is repainted without disposing of the previous one is a good idea...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I have object A, operating in the program's main thread, which creates several copies of object B (B1, B2, etc) and executes them in several threads.
I have figured out how to get A to raise a custom event that B2 should deal with. Since A knows all about the objects it created, it simply calls B2.OnBEvent() .
However, I now want a B object (say B3) to raise an event for A to deal with. B3 does not know about the object A (no reference to A has been passed to B3), so it can't call A.OnAEvent() .
My question is, can I declare an OnAEvent() method to be static, so that B3 does not have to know about object A? Can I call ClassA.OnAEvent() and have that event handled by object A?
BTW: in the on-going conflict between how threading is done and how Clive Pottinger thinks threading is done, the score now stands at 43 - 0.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Perhaps make it a static event and make the "child" classes register for the event when they're created?
|
|
|
|
|
That is what I was asking - is setting up a static event possible.
I know I could simply pass a reference to A to B1, B2, B3, etc. Then the B's would have no problem raising an event for A to deal with. I was just wondering if there is a way to do this without having to pass that reference to A.
I'll see if I can find out how to create a static event. I haven't yet run across examples or documentation showing that being done.
Clive Pottinger
Victoria, BC
|
|
|
|
|
public class A
{
public static event EventHandler<YourEventArgs> GlobalEvent;
public A()
{
A.GlobalEvent += new EventHandler<YourEventArgs>(delegate void (YourEventArgs e)
{
});
}
}
|
|
|
|
|
What you are describing are not really events, but method calls. Take a look at C# event s and delegate s, any documentation you find on them will show you how to use them. When A creates instances of Bs, it can register itself with B events and visa versa.
Only set up static events on A if it makes sense to do so. Most often it will make more sense for the instance to process events. Just google "C# event", I'm sure that will get you plenty of starting points.
Hope that helps.
|
|
|
|
|
Actually, I was talking about the events. In my examples I was just showing the calls to the methods that raise the events for simplicity.
It would seem, from your reply, that it is possible to set up a static event the class A. Whether or not that is better is better than passing A to the B's so they can register the event...? I'll try and see.
Clive Pottinger
Victoria, BC
|
|
|
|
|
I apologize for the assumption, from your post I wasn't sure you were actually using events.
I don't think you'll need static events, unless that's what you want to do. If B has an event, when A creates those instances it should be able to hook the new B instance's events to a method of it's own. Also on creation of the B instances, you can set them up as subscribers to events that A has.
Is this the kind of thing you're talking about? Or did I completely misunderstand your question?
class A {
public event EventHandler OnA;
public void Start() {
B b1 = new B(1);
b1.OnB += new EventHandler(CatchOnB);
OnA += new EventHandler(b1.CatchOnA);
B b2 = new B(2);
b2.OnB += new EventHandler(CatchOnB);
OnA += new EventHandler(b2.CatchOnA);
b1.DoStuff();
b2.DoStuff();
if (OnA != null) {
OnA(this, EventArgs.Empty);
}
}
private void CatchOnB(object sender, EventArgs e) {
Console.WriteLine("B{0} called me", ((B)sender).Id);
}
}
class B {
public event EventHandler OnB;
public int Id;
public B(int id) {
this.Id = id;
}
public void CatchOnA(object sender, EventArgs e) {
Console.WriteLine("A called B{0}", Id);
}
public void DoStuff() {
if (OnB != null) {
OnB(this, EventArgs.Empty);
}
}
}
|
|
|
|
|
Thank you, BoneSoft.
I had missed this post way back when, and only just saw it today. This answers my question nicely. I wish I had noticed it before.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Sure thing. Hope it helps.
Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.
|
|
|
|
|
A should register the events it wants to listen to on B when it creates them.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
cpotting wrote: so that B3 does not have to know about object A?
Yeah that's a very common problem in software design.
cpotting wrote: Can I call
There may be many things you can do, but likely a sub set of them that are considered best practice. You could do some studying of Software Design Patterns that would shed some light on this subject for you, if you wanted to.
led mike
|
|
|
|
|
have a report that contain at least 7 subreports. Each with their own datasource. I have set the subreports datasource to the correct datasource and on a few of them passed in parameters.
however, upon running it I noticed that the reports would show "SubReport cannot be shown". I made sure my parameters were being passed and its of the same type.
I googled and found a lot of examples that used the 'LocalReport_SubreportProcessing' event to populate the datasources for each subreport.
Is this the right way to go about it? I cannot find any good examples of how to populate a subreport. I need to justify putting the logic like this inside the ReportViewer form rather than someplace else.
Could someone please shed some light on this for me?
I am using VS 2005 C#, Sql 2k, on Windows Server 2003. I am using Reporting Services however the reports in my project are .rdlc files not .rdl they are inside my Windows Project not a Reporting Project...if this matters.
Any help asap would be greatly appreciated. Below is a small sample of how im using the event.
void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
if(ReportEmbeddedResource =="Desktop_Controller.Reports.Desktop_Controller.Reports.rptPatientInfo.rdlc")
{
System.Diagnostics.Debug.Write("SubReport being processed: " + e.ReportPath + "\r\n");
try
{
switch (e.ReportPath)
{
case "rsubPatientInfoReferred":
if (null == vwReferrals)
{
VwPatientInfoReferralsService vwSer = new VwPatientInfoReferralsService();
vwReferrals = vwSer.GetAll();
}
vwReferrals.Filter = "PatientNumber = '" + PatientNumber + "'";
e.DataSources.Add(new ReportDataSource("StVincent_Bariatrics_DomainModel_VwPatientInfoReferrals", vwReferrals));
break;
}
}
catch{}
}
}
Steve Welborn
Software Engineer
Inrange Consulting
modified on Friday, January 25, 2008 1:49:29 PM
|
|
|
|
|
Hello, I want to deploy a web service that exposes an Access database to clients, the database file is located in the App_Data folder in the service's folder.
The problem is that I have to set the security settings for that file manually using NTFS security tab in the properties window of the database file to allow the account "ASPNET" to write to the database.
Is there a way to do this during the setup process? I have wondered around the setup project I created for the web service and I had no clue on how to do this.
|
|
|
|
|
Wassim Mansour wrote: Is there a way to do this during the setup process?
Of course
Wassim Mansour wrote: I had no clue on how to do this.
If it is a Windows Installer check out Installsite.org[^]
led mike
|
|
|
|
|
On my form paint method i drew this ellipse but how can i make this circle transparent so if i put this ellipse on the top of another object it becomes transparent.
Graphics g = e.Graphics;
Rectangle r = new Rectangle();
r.Size = this.Bounds.Size;
GraphicsPath ca = new GraphicsPath();
ca.AddEllipse(r);
Region region = new Region(ca);
this.Region = region;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawEllipse(new Pen(Brushes.Red), Rectangle.Inflate(r, -1, -1));
g.FillEllipse(Brushes.AntiqueWhite, Rectangle.Inflate(r, -3, -3));
|
|
|
|
|
I don't think the 2D Drawing methods are object aware and you would likely have to create your own code, which would be slow.
One thing I do know, however, is that AntiAlias should not be applied until after the transparency or you will get a glow.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|