Shape Without Form

March 2006 Entries

VStudio Publish Web Site Problems

I have been busy working on an ASP.Net 2.0 application for deployment to what has up until now been 1.1.x IIS server only.

I  used the new Publish to Web feature. I thought “sweet” it is much simpler than some around the world deployment steps I had to go through before due to the nature of my work's network and my (lowly) permissions.

After depoloyment, I go to test the site, and it fails when readinig the config file.  At fist I assumed the network guy had not installed 2.0 frame work like he was supposed to. (this was true) but it still failed after he did his job.

Looking around the web I came across a “bug“ wich is good to know in case it happens to you. In short the bug is when a 2.0 web is created in a 1.1. subnet and the fix is  “ to *not* create an Application in the root“.

But that wasn't the problem either. After jumping through some internal hoops I am able to look at the web site in IIS.

Guess what? It created the Website to run as ASP.Net 1.1.4322  not ASP.NET 2.0.50727 How bizzare is that? Deploy a 2005 solution and it doesn't create it as 2.0? An oddity for sure, perhaps there is a config setting in  VStudio.

Anyway, a very simple solution once I was able to see what was going on. And I do like the 'deploy to web functionality'. Do wish there was an option to selectivly publish items as oppesed to all or nothing though.

 

 

 

Wow, the how did they do that feeling hits home.

I am sure I am behind the times. But if you haven't see this site you must check it out.

http://www.pageflakes.com/Default.aspx#

 Plus the amazing home page of one of the developers

http://omar.mvps.org/

And No Evil Smell!

Just had to make at least one comment about the Microsoft orgasm origami.

First, regarding over hype, I don't think you can blame M$ for that.  

While I don't think it will be all that useful (Though reading E-books would be cool) and probably not all that useful for on the go development, unless your a good text editor,  a PDA with a higher resolution and larger screen would be much appreciated. But how good can it be without a key board? Even the version where they show with one it  looks too small to be useful, unless your a Smurf.  How could they have a useful keyboard anyway and it still be portable. 

This lead me to thinking. [Has been known to the state of California to cause cancer, I know, but I live on the edge]  I had the next great idea for making $$$. I was already envisioning my own IPO... fold up keyboards, not the small kind that collapse into a cube with hinges, but something like the piano keyboard my 4 year old has. it is plastic and thinn like paper. You can roll it as well as fold it. Image you have one of these "fully functional" PCs (though how functional a watered down CPU can be I don't know.) and you pull a keyboard out of your back pocket. Unfold it and have a full size keyboard, Hell, I want one for my PDA. I have a hard time using my IPAQ as I want to, because entering data is too time consuming.

So, to see if it was feasible I did a quick google and found, yet again, I have been beat out.

 

This was pretty funny - read the number one feature  excerpt for this one:
Roll- keyboard
1.High-quality silicone.No poisonous and evil smell.

 

 
  No poisonous and evil smell!  

My firewall needs some ruffage.

Port Seems to be blocked!
As Mike Flasko asked in a comment and I suspected yesterday but didn't get around to checking; it looks like my pc here can't connect via SMTP to Gmail. I attempted with telnet, and receive the same error that .net reported.  May be I can find some time today to try System.Net.Mail with the exchange server here.

GDI+ Example

GDI+ Drawing outside the lines
  

 

GDI+ Drawing out side the lines


I would like to present two simple concepts:

  • How to create a Graphics object without using an OnPaint Event and its PaintEventArgs.
  • How to get the coordinates for an existing control and draw on it.



It is possible to override OnPaint events.

Overriding the Form's OnPaint:

 
protected override void OnPaint(PaintEventArgs pe)? 
{
 
}
 

Then you will have to get a reference to the graphics object:

 
Graphics g = pe.Graphics;
 

What if, however, we want to click a button and draw shapes on the form?
Or what if we want to draw around a text box to highlight the work area?
How do we get a PaintEventArg ?

Well, luckily we don't have too.

We have been provided with a constructor method.

 
Graphics g = CreateGraphics();
 

That's it. That's all we have to do to create a Graphics object. Now what do we do with it?

Lets go with my idea above and draw rectangles around controls when they receive focus so the user will know where they are on the form.
As seen below.

Get started:

1. In Visual Studio start a new Win32 app.
2. Add a few controls.
3. Make sure to add the necessary Name Spaces

 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D; //This is where the Graphics object comes from)
 

Now lets get the coordinates and draw some boxes:

Add this in your Form's class area after the static void Main() declaration.

 
private void PaintMe( Control controlToPaint)
{
Graphics g = CreateGraphics();
 
//Create a Pen object set color to Yellow and Size to 5
Pen pen = new? Pen (Color.Yellow,5);??? 
Pen pen2 = new Pen (Color.Black,7);
 
// This pen2 will be used to add a border around our first box - so it will?? stand out more.
 
//Get the controls Coordinates
int p1 = controlToPaint.Left;
int p2 = controlToPaint.Top;
 
int p3 = controlToPaint.Width;
 int p4 = controlToPaint.Height;
 
 g.DrawRectangle(pen2,p1,p2,p3,p4);
 
 //Draw the Border first or it will cover the yellow
 g.DrawRectangle(pen,p1,p2,p3,p4);
 // Draw the yellow Box
}
 

What we just did:

Instantiated a Graphics and a Pen object.

The DrawRectangle method needs the X-Coordinate of the Top left starting position of the rectangle.
The Y-Coordinate of upper left of the rectangle,
the Width, and the Height of the rectangle.
To get this we got the left, the top, the width, and the height from the control we passed in respectfully.

Now we have a function that accepts a Control and draws a box around it.

The only thing left is to tie this to an event.
Since we want the control highlighted when the user goes to enter information lets add it to the Enter event.

In Visual Studio go to the Form1.cs[Design] view and right click a control and choose properties.
Click the lightening bolt to get to the events.
Go to the Enter event and type in getPainted, press enter to go to code view. Add the PaintMe call.

 
private void getPainted(object sender,System.EventArgs e)
{
PaintMe((Control)sender);? //Cast the object to a Control
}
 

Or if you don't have Visual Studio make sure to add this to your code: private void InitializeComponent() Section - (Please see full code if this isn't clear.)

 
this.yourControlName.Enter += new System.EventHandler(this.getPainted);
 

Ok, One more thing. We probably want the box to go away when the focus is on to another control.

So create one more function:

 
private void refreshForm(object sender,System.EventArgs e)
{
Form1.ActiveForm.Refresh() ; //Repaint the form and erase our drawings
}
 

Keep in mind that any time the form is repainted (like if you move it)your drawings will go away.
Here that is a good thing for us.
So call this from the Leave event like we did for the Enter.
Or add it yourself:

 
this.yourControlName.Leave += new System.EventHandler(this.refreshForm);
 

Pretty neat huh? This could be used for errors, for showing the next location to go to, show missing information on a form. You get the idea.

Now that you know how to create a Graphics object any time you want too, have fun and play with all the drawing methods.

Have fun.

Complete Source:

 Complete Source:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//using System.Data;
//using System.IO;
using System.Drawing.Drawing2D;
namespace GDISample
{
    /// 
    /// Summary description for Form1.
    /// 
    public class Form1 : System.Windows.Forms.Form
    {
 
        private System.Windows.Forms.ComboBox comboBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.CheckBox checkBox1;
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.Container components = null;
 
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
 
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
 
        /// 
        /// Clean up any resources being used.
        /// 
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        
 
        #region Windows Form Designer generated code
        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.SuspendLayout();
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(16, 32);
            this.textBox2.Multiline = true;
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(144, 64);
            this.textBox2.TabIndex = 4;
            this.textBox2.Text = "textBox2";
            
            this.textBox2.Leave += new System.EventHandler(this.refreshForm);
            this.textBox2.Enter += new System.EventHandler(this.getPainted);
            // 
            // comboBox1
            // 
            this.comboBox1.DropDownWidth = 136;
            this.comboBox1.Location = new System.Drawing.Point(176, 32);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(112, 21);
            this.comboBox1.TabIndex = 3;
            this.comboBox1.Text = "comboBox1";
            this.comboBox1.Leave += new System.EventHandler(this.refreshForm);
            this.comboBox1.Enter += new System.EventHandler(this.getPainted);
            // 
            // listBox1
            // 
            this.listBox1.Location = new System.Drawing.Point(16, 112);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(144, 95);
            this.listBox1.TabIndex = 5;
            this.listBox1.Leave += new System.EventHandler(this.refreshForm);
            this.listBox1.Enter += new System.EventHandler(this.getPainted);
            // 
            // checkBox1
            // 
            this.checkBox1.Location = new System.Drawing.Point(184, 72);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(104, 32);
            this.checkBox1.TabIndex = 6;
            this.checkBox1.Text = "checkBox1";
            this.checkBox1.Enter += new System.EventHandler(this.getPainted);
            this.checkBox1.Leave += new System.EventHandler(this.refreshForm);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(744, 557);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.checkBox1,
                                                                          this.listBox1,
                                                                          this.textBox2,
                                                                          this.comboBox1});
            this.Name = "Form1";
            this.Text = "Form1";
            this.Enter += new System.EventHandler(this.getPainted);
            this.ResumeLayout(false);
 
        }
        #endregion
 
        /// 
        /// The main entry point for the application.
        /// 
        [STAThread]
        
 
        static void Main() 
        {
            Application.Run(new Form1());
        }
        
        
 
        private void PaintMe( Control controlToPaint)
        {
            //Create A Graphics obj
             Graphics g = CreateGraphics(); 
            //Create a Pen obj set color to RED and Size to 5
            Pen pen = new Pen(Color.Yellow,5);
// This pen will be used to add a border around our other so it will stand out more.
    
            Pen pen2 = new Pen(Color.Black,7);            
            //Get the controls Coordinants
 
            int p1 = controlToPaint.Left;
 
            int p2 = controlToPaint.Top;
                            
            int p3 = controlToPaint.Width;
 
            int p4 = controlToPaint.Height;
/*The DrawRectangle Method requires a Pen,The X-Coordinate of Top Left,The Y-Coordinate of upper left
 
  The Width, The Height)*/
 
            
            g.DrawRectangle(pen2,p1,p2,p3,p4); //Draw the Border first or it will cover the yellow
        
            g.DrawRectangle(pen,p1,p2,p3,p4); // Draw the yellow Box
            
        }        
        
        
        private void getPainted(object sender,System.EventArgs e)
        {
                PaintMe((Control)sender);//Cast the object to a Control
        }
 
        
 
        private void refreshForm(object sender,System.EventArgs e)
        {
                 Form1.ActiveForm.Refresh() ; //Repaint the form and erase our drawings
        }
 
        
        
        } 
        
    }
 
 
 
 
 
 

 

Ayman's VB .Net.Mail to C#

Thought Ayman's snip was pretty cool System.net.mail with Gmail account  I hadn't looked at this part of the namespace.

Here it is with squigles, pretty much the same.

I have been unable to connect the gmail smtp server though and will show my error first...

The Error I get:

Failure sending mail.
System.Net.WebException: Unable to connect to the remote server ---> System.Net.
Sockets.SocketException: An established connection was aborted by the software i
n your host machine
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object ow
ner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket
6, Int32 timeout)
   at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32
 timeout, GeneralAsyncDelegate asyncCallback)
   at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate
 asyncCallback)
   at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncD
elegate asyncCallback, Int32 creationTimeout)
   at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
   at System.Net.Mail.SmtpClient.GetConnection()
   at System.Net.Mail.SmtpClient.Send(MailMessage message)

Has System.Net.NetworkCredential changed in VS 2005?

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Mail;

namespace ConsoleMailSend

{

public static class MailMaker

{

public static void sendmail()

{

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

string msgBody =string.Empty;

System.Net.Mail.SmtpClient smtp =new SmtpClient();

mail.From = new System.Net.Mail.MailAddress(@"ur-email@gmail.com", "c");

mail.To.Add(@"an-email@adomain.com");

mail.Subject = "Subject";

mail.Body = "msgBody";

mail.IsBodyHtml = true ;// This is to enable HTML in your email body

mail.ReplyTo = new MailAddress(@"ur_email@rd.com") ; // This is optional, it allows you to add Reply To email address.

smtp.Host = "smtp.gmail.com";

smtp.Port = 25;

smtp.EnableSsl = true;

smtp.Credentials = new System.Net.NetworkCredential(@"ur-email@gmail.com", "password");

try

{

smtp.Send(mail);

}

catch (System.Exception ex)

{

Console.WriteLine(ex.Message.ToString());

Console.WriteLine(ex.InnerException.ToString());

}

}

}

}

Anyone out there have any hangups?

I have been having some lower back issues has anyone out there  tried out inversion thearapy?

How did it go for you?

Teeter Hangup Inversion Boots