Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Drawing applet RSS

27 replies

Last post Sep 24, 2008 12:14 AM by RezaMohamed

(1)
  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Drawing applet

    Sep 16, 2008 04:23 PM | LINK

    I had created a simple drawing applet in SL2 beta 1 and it worked just fine, now with the new release (sl2 beta2) it doesnt work. can someone help me debug what the problem is, ive looked at it for way too long to no avail. another set of eyes might catch something that I cant see.

     thanks

     

     c#

    1        public partial class Page : UserControl
    2        {
    3            private Point mouseDownPoint = new Point();
    4   
    5            public Page()
    6            {
    7                InitializeComponent();
    8   
    9                canvasBlackboardArea.MouseEnter += new MouseEventHandler(canvasBlackboardArea_MouseEnter);
    10               canvasBlackboardArea.MouseLeftButtonDown += new MouseButtonEventHandler(canvasBlackboardArea_MouseLeftButtonDown);
    11               canvasBlackboardArea.MouseLeftButtonUp += new MouseButtonEventHandler(canvasBlackboardArea_MouseLeftButtonUp);
    12               canvasBlackboardArea.MouseLeave += new MouseEventHandler(canvasBlackboardArea_MouseLeave);
    13           }
    14  
    15           void canvasBlackboardArea_MouseLeave(object sender, MouseEventArgs e)
    16           {
    17               this.canvasBlackboardArea.Cursor = Cursors.Arrow;
    18  
    19               canvasBlackboardArea.MouseMove -= new MouseEventHandler(canvasBlackboardArea_MouseMove);
    20           }
    21  
    22           void canvasBlackboardArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    23           {
    24               canvasBlackboardArea.MouseMove -= new MouseEventHandler(canvasBlackboardArea_MouseMove);
    25           }
    26  
    27           void canvasBlackboardArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    28           {
    29  
    30               mouseDownPoint = e.GetPosition(this.canvasBlackboardArea);
    31  
    32               PathFigure myPathFigure = new PathFigure() { StartPoint = new Point(0, 0) };
    33  
    34               LineSegment myLineSegment = new LineSegment() { Point = new Point(0, 0) };
    35  
    36               PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
    37               myPathSegmentCollection.Add(myLineSegment);
    38  
    39               myPathFigure.Segments = myPathSegmentCollection;
    40  
    41               PathFigureCollection myPathFigureCollection = new PathFigureCollection();
    42               myPathFigureCollection.Add(myPathFigure);
    43  
    44               PathGeometry myPathGeometry = new PathGeometry() { Figures = myPathFigureCollection };
    45  
    46               Path myPath = new Path();
    47               myPath.Stroke = new SolidColorBrush(Colors.Black);
    48               myPath.StrokeThickness = 3;
    49               myPath.Data = myPathGeometry;
    50  
    51               canvasBlackboardArea.Children.Add(myPath);
    52  
    53               myPath.SetValue(Canvas.TopProperty, mouseDownPoint.X);
    54               myPath.SetValue(Canvas.LeftProperty, mouseDownPoint.Y);
    55  
    56               canvasBlackboardArea.MouseMove += new MouseEventHandler(canvasBlackboardArea_MouseMove);
    57  
    58           }
    59  
    60           void canvasBlackboardArea_MouseMove(object sender, MouseEventArgs e)
    61           {
    62               Path path = canvasBlackboardArea.Children[canvasBlackboardArea.Children.Count - 1] as Path;
    63  
    64               if (path != null)
    65               {
    66                   PathGeometry pathgeometry = path.Data as PathGeometry;
    67                   PathFigure figure = pathgeometry.Figures[0] as PathFigure;
    68                   Point p = e.GetPosition(this.canvasBlackboardArea);
    69  
    70                   //p.Offset(-mouseDownPoint.X, -mouseDownPoint.Y);
    71  
    72                   p.X -= mouseDownPoint.X;
    73                   p.Y -= mouseDownPoint.Y;
    74  
    75                   LineSegment myLineSegment = new LineSegment() { Point = p };
    76                   //figure.IsClosed = true;
    77                   figure.Segments.Add(myLineSegment);
    78               }
    79           }
    80  
    81           void canvasBlackboardArea_MouseEnter(object sender, MouseEventArgs e)
    82           {
    83               canvasBlackboardArea.Cursor = Cursors.Stylus;
    84           }
    85       }

     

    xaml

        <Grid x:Name="LayoutRoot" Background="White">
    
            <Canvas Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Margin="2.5,2.5,2.5,2.5" Background="#FFF6E90C" x:Name="canvasBlackboardArea"/>
    
    
        </Grid>
    

     

    to make things easier, I have included the source files in VS2008 project format here.

     

    thanks 

     

  • HarshBardhan

    HarshBardhan

    Star

    10118 Points

    1749 Posts

    Re: Drawing applet

    Sep 16, 2008 04:32 PM | LINK

    Hi Reza,

    It is Working at my end Reza.

    Can you let me know which feature is not working for you or what error are you getting..

    I can not download any content from RapidShare(Sorry for tat).. 

    Mark as answer if this post answered your question.

    Harsh Bardhan
  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Re: Drawing applet

    Sep 16, 2008 04:48 PM | LINK

    so you are saying that you can:

     mouse down click ---> drag (move mouse around)  ::::  and it draws while you drag?

     for me it seems that when i click and drag..it doesnt display anything on the screen, when i mouse up, and then click again, it draws an arbitrary line somewhere on the canvas but not where i mousedown.

     it is def NOT working correctly on my end.

     ALSO, are you workign with SL2 beta2? like i said, it was workign fine on beta 1, and its giving me problems now with beta2.

     

  • kwatts

    kwatts

    Contributor

    2159 Points

    436 Posts

    Re: Drawing applet

    Sep 16, 2008 04:49 PM | LINK

    I downloaded your project and was able to build and run it.  I'm not sure what the application is supposed to do, so I could not find a problem with it.  Can you describe exactly what the problem is?  I'm wondering if you did not install the new chainer correctly.  It requires that you uninstall a KB, so you may want to review this. 

    Note if this was helpful, please mark it as an answer, thanks!

    -Ken

     


    http://kenwatts.blogspot.com/


    Please select "Mark as Answer" for posts that are helpful. Thanks!
  • HarshBardhan

    HarshBardhan

    Star

    10118 Points

    1749 Posts

    Re: Drawing applet

    Sep 16, 2008 04:51 PM | LINK

    Same thing is Happening at my end also..

    I thought you are getting some error in that also...

    I can check that and i can let you know ..

    Probably we need to modify our handler

    Mark as answer if this post answered your question.

    Harsh Bardhan
  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Re: Drawing applet

    Sep 16, 2008 04:51 PM | LINK

    basically...just draws on the canvas like you would with chalk on teh blackboard!

    I am not aware of any kb problems with sl2 beta2..do you have a link to this? thanks

     

    EDIT:

    Ken, can you verify if you are able to draw on the canvas seamlessly like you would write on paper please. looks like the last poster had similar experiences with my code, so im wondering if its the code or the KB problem you mention. thanks

  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Re: Drawing applet

    Sep 16, 2008 05:05 PM | LINK

    HarshBardhan

    Same thing is Happening at my end also..

    I thought you are getting some error in that also...

    I can check that and i can let you know ..

    Probably we need to modify our handler

    thanks Harsh

  • kwatts

    kwatts

    Contributor

    2159 Points

    436 Posts

    Re: Drawing applet

    Sep 16, 2008 06:22 PM | LINK

    RezaMohamed

    basically...just draws on the canvas like you would with chalk on teh blackboard!

    I am not aware of any kb problems with sl2 beta2..do you have a link to this? thanks

     

    EDIT:

    Ken, can you verify if you are able to draw on the canvas seamlessly like you would write on paper please. looks like the last poster had similar experiences with my code, so im wondering if its the code or the KB problem you mention. thanks

     

    Here's the link to the chainer install:

    http://www.microsoft.com/downloads/details.aspx?FamilyId=50A9EC01-267B-4521-B7D7-C0DBA8866434&displaylang=en

    It says to remove KB949325.  But I'm guessing that this is not the problem.

    I think I see what you're talking about though - it's not very smooth.  I think that it has to do with adding and removing mouse event handlers.  It would probably behave better if you kept the same handler in place for the duration of the program.  I'll do some more testing and let you know what I find.

    -Ken 

     


    http://kenwatts.blogspot.com/


    Please select "Mark as Answer" for posts that are helpful. Thanks!
  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Re: Drawing applet

    Sep 16, 2008 07:24 PM | LINK

    thanks for the link for the kb.

    i checked my installs..i dont have that kb. so it doesnt look like a kb issue. it definitely seems like a migration issue from SL2 beta 1 to beta 2. I have another machine with beta 1 and it seems to work just fine.

    Any ideas?

  • RezaMohamed

    RezaMohamed

    Member

    520 Points

    322 Posts

    Re: Drawing applet

    Sep 17, 2008 11:03 AM | LINK

    help [:(]