Страница:  1   | 2   | 3   | 
		
		
			
	
		 
		
			
  
      
    
Вопрос: Сохранить графику  
     
    
Добавлено:  10.01.11 16:41 
     
      
   
		
			
			  
		
			
		
		
			
		
	  
	  
    
      
Номер ответа:  17Автор ответа:   romashko1901  
ICQ:  416844272 Вопросов:  1Ответов:  13 
       
      
 Профиль  |  | #17 
       
Добавлено:   12.01.11 14:41
       
     
    
      
EROS 
 
Imports  System.Collections.Generic
 
Imports  System.Drawing
 
Imports  System.Drawing.Drawing2D
 
Imports  System.Windows.Forms
 
  
Namespace  VbNetSample
 
  
    Partial Public  Class  Form1
 
        Inherits  Form
 
        Private  m_shapeManager As  ShapeManager
 
        Private  m_currentColor As  Color
 
        Private  m_currentShape As  ShapeType
 
        Private  m_lastPoint As  Point
 
        Private  m_is_pressed As  Boolean 
 
        Private  m_currentWidth As  Single 
 
  
        Public  Sub  New ()
 
            Initialize()
 
        End  Sub 
 
  
        Private  Sub  Initialize()
 
            BackColor = Color.White
 
            DoubleBuffered = True 
 
  
            m_shapeManager = New  ShapeManager()
 
            m_currentColor = Color.Blue
 
            m_currentShape = ShapeType.Line
 
            m_currentWidth = 10.0F
 
        End  Sub 
 
  
        Protected  Overrides  Sub  OnMouseDown(ByVal  e As  MouseEventArgs)
 
            If  e.Button = MouseButtons.Left Then 
 
                m_lastPoint = e.Location
 
                m_is_pressed = True 
 
            End  If 
 
        End  Sub 
 
  
        Protected  Overrides  Sub  OnMouseUp(ByVal  e As  MouseEventArgs)
 
            If  e.Button = MouseButtons.Left Then 
 
                m_is_pressed = False 
 
            End  If 
 
        End  Sub 
 
  
        Protected  Overrides  Sub  OnMouseMove(ByVal  e As  MouseEventArgs)
 
            If  m_is_pressed Then 
 
                Select  Case  m_currentShape
 
                    Case  ShapeType.Line
 
                        AppendShape(New  Line(m_currentColor, m_lastPoint, e.Location, m_currentWidth))
 
                        m_lastPoint = e.Location
 
                        Exit  Select 
 
                    Case  Else 
 
                        Throw  New  NotImplementedException()
 
  
                End  Select 
 
            End  If 
 
        End  Sub 
 
  
        Private  Sub  AppendShape(ByVal  shape As  IShape)
 
            m_shapeManager.Add(shape)
 
            UpdateImage()
 
        End  Sub 
 
  
        Protected  Overrides  Sub  OnPaint(ByVal  e As  PaintEventArgs)
 
            MyBase .OnPaint(e)
 
  
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality
 
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality
 
  
            For  Each  shape As  IShape In  m_shapeManager
 
                shape.Draw(e.Graphics)
 
            Next 
 
        End  Sub 
 
  
        Private  Sub  Undo()
 
            If  m_shapeManager.Count <> 0 Then 
 
                m_shapeManager.RemoveAt(m_shapeManager.Count - 1)
 
                UpdateImage()
 
            End  If 
 
        End  Sub 
 
  
        Private  Sub  UpdateImage()
 
            Refresh()
 
            Text = String .Format("Объектов: {0}" , m_shapeManager.Count)
 
        End  Sub 
 
    End  Class 
 
  
  
    Public  Enum  ShapeType
 
        Line
 
        Rectangle
 
        Star
 
        Cycle
 
    End  Enum 
 
    Public  Interface  IShape
 
        Sub  Draw(ByVal  g As  Graphics)
 
    End  Interface 
 
  
    <Serializable()> _
 
    Public  Class  Line
 
        Implements  IShape
 
        Public  Sub  New ()
 
        End  Sub 
 
        Public  Sub  New (ByVal  color__1 As  Color, ByVal  begin__2 As  Point, ByVal  end__3 As  Point, ByVal  width__4 As  Single )
 
            Color = color__1
 
            Begin = begin__2
 
            [End ] = end__3
 
            Width = width__4
 
        End  Sub 
 
  
        Public  Property  Color() As  Color
 
            Get 
 
                Return  m_Color
 
            End  Get 
 
            Set (ByVal  value As  Color)
 
                m_Color = Value
 
            End  Set 
 
        End  Property 
 
        Private  m_Color As  Color
 
        Public  Property  Begin() As  Point
 
            Get 
 
                Return  m_Begin
 
            End  Get 
 
            Set (ByVal  value As  Point)
 
                m_Begin = Value
 
            End  Set 
 
        End  Property 
 
        Private  m_Begin As  Point
 
        Public  Property  [End ]() As  Point
 
            Get 
 
                Return  m_End
 
            End  Get 
 
            Set (ByVal  value As  Point)
 
                m_End = Value
 
            End  Set 
 
        End  Property 
 
        Private  m_End As  Point
 
        Public  Property  Width() As  Single 
 
            Get 
 
                Return  m_Width
 
            End  Get 
 
            Set (ByVal  value As  Single )
 
                m_Width = Value
 
            End  Set 
 
        End  Property 
 
        Private  m_Width As  Single 
 
  
        Public  Sub  Draw(ByVal  g As  Graphics) Implements  IShape.Draw
 
            Using pen As  New  Pen(Color, Width)
 
                pen.StartCap = LineCap.Round
 
                pen.EndCap = LineCap.Round
 
                g.DrawLine(pen, Begin, [End ])
 
            End  Using
 
        End  Sub 
 
  
    End  Class 
 
  
    Public  Class  ShapeManager
 
        Inherits  List(Of IShape)
 
        Public  Shared  Function  FromFile(ByVal  path As  String ) As  ShapeManager
 
             
            Return  Nothing 
 
        End  Function 
 
        Public  Sub  Save(ByVal  path As  String )
 
             
        End  Sub 
 
    End  Class 
 
End  Namespace 
 
 
 
На vb перевел, теперь можете вратце объяснить что к чему?
Ответить 
      
 
     
  
	  
	  
    
      
Номер ответа:  19Автор ответа:   romashko1901  
ICQ:  416844272 Вопросов:  1Ответов:  13 
       
      
 Профиль  |  | #19 
       
Добавлено:   12.01.11 14:48
       
     
    
      
EROS  пишет: 
 
Заработало? 
 
Нет, может на форму нужно что то добавить?
 
EROS  пишет: 
 
Namespace у тебя другой будет. 
 
Какой? как называется проект?
Ответить 
      
 
     
  
	  
	  
	  
    
      
Номер ответа:  22Автор ответа:   romashko1901  
ICQ:  416844272 Вопросов:  1Ответов:  13 
       
      
 Профиль  |  | #22 
       
Добавлено:   12.01.11 14:59
       
     
    
      
EROS  пишет: 
 
Namespace оставь тот который у тебя был.. т.е. вместо VbNetSample у тебя должно быть что то типа WindowsApplication1 или как то так 
 
Когда создаю новый проект, появляется окно с формой вхожу в режим кода(F7) там есть Public  Class  Form1
 
  
End  Class  
 
и больше ничего, заменяю все тем, что Вы написали - запускается программа и все. кликаю, вожу мышкой и ничего не появляется. пробывал namespace заменить на WindowsApplication1 то же самое...что то не могу понять как использовать теперь эти классы?
Ответить 
      
 
     
  
	  
	  
    
      
Номер ответа:  24Автор ответа:   romashko1901  
ICQ:  416844272 Вопросов:  1Ответов:  13 
       
      
 Профиль  |  | #24 
       
Добавлено:   12.01.11 18:39
       
     
    
      
EROS  пишет: 
 
Inherits Form и Partial 
 
Может потому что у меня VB.Net 2010, либо потому что не C#?
Ответить 
      
 
     
  
	  
	  
    
      
Номер ответа:  26Автор ответа:   Дмитрий Юпатов  
Вопросов:  4Ответов:  457 
       
      
 Web-сайт:  cargomaster.at.ua/   Профиль  |  | #26 
       
Добавлено:   12.01.11 21:13
       
     
    
      
Imports  System.Collections.Generic
 
  
Imports  System.Drawing
 
  
Imports  System.Drawing.Drawing2D
 
  
Imports  System.Windows.Forms
 
  
  
Public  Class  Form1
 
  
    Inherits  Form
 
  
    Private  m_shapeManager As  ShapeManager
 
  
    Private  m_currentColor As  Color
 
  
    Private  m_currentShape As  ShapeType
 
  
    Private  m_lastPoint As  Point
 
  
    Private  m_is_pressed As  Boolean 
 
  
    Private  m_currentWidth As  Single 
 
  
  
    Public  Sub  New ()
 
  
        Initialize()
 
  
    End  Sub 
 
  
  
    Private  Sub  Initialize()
 
  
        BackColor = Color.White
 
  
        DoubleBuffered = True 
 
  
  
        m_shapeManager = New  ShapeManager()
 
  
        m_currentColor = Color.Blue
 
  
        m_currentShape = ShapeType.Line
 
  
        m_currentWidth = 10.0F
 
  
    End  Sub 
 
  
  
    Protected  Sub  _OnMouseDown(ByVal  sender As  Object , ByVal  e As  MouseEventArgs) Handles  MyBase .MouseDown
 
  
        If  e.Button = MouseButtons.Left Then 
 
  
            m_lastPoint = e.Location
 
  
            m_is_pressed = True 
 
  
        End  If 
 
  
    End  Sub 
 
  
  
    Protected  Sub  _OnMouseUp(ByVal  sender As  Object , ByVal  e As  MouseEventArgs) Handles  MyBase .MouseUp
 
  
        If  e.Button = MouseButtons.Left Then 
 
  
            m_is_pressed = False 
 
  
        End  If 
 
  
    End  Sub 
 
  
  
    Protected  Sub  _OnMouseMove(ByVal  sender As  Object , ByVal  e As  MouseEventArgs) Handles  MyBase .MouseMove
 
  
  
        If  m_is_pressed Then 
 
  
            Select  Case  m_currentShape
 
  
                Case  ShapeType.Line
 
  
                    AppendShape(New  Line(m_currentColor, m_lastPoint, e.Location, m_currentWidth))
 
  
                    m_lastPoint = e.Location
 
  
                    Exit  Select 
 
  
                Case  Else 
 
  
                    Throw  New  NotImplementedException()
 
  
  
            End  Select 
 
  
        End  If 
 
  
    End  Sub 
 
  
  
    Private  Sub  AppendShape(ByVal  shape As  IShape)
 
  
        m_shapeManager.Add(shape)
 
  
        UpdateImage()
 
  
    End  Sub 
 
  
    Private  Sub  rightclick(ByVal  sender As  Object , ByVal  e As  MouseEventArgs) Handles  MyBase .MouseClick
 
        If  e.Button = Windows.Forms.MouseButtons.Right Then 
 
            Me .Undo()
 
        End  If 
 
    End  Sub 
 
  
    Protected  Sub  _OnPaint(ByVal  sender As  Object , ByVal  e As  PaintEventArgs) Handles  MyBase .Paint
 
  
         
  
  
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality
 
  
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
 
  
  
        For  Each  shape As  IShape In  m_shapeManager
 
  
            shape.Draw(e.Graphics)
 
  
        Next 
 
  
    End  Sub 
 
  
  
    Private  Sub  Undo()
 
  
        If  m_shapeManager.Count <> 0 Then 
 
  
            m_shapeManager.RemoveAt(m_shapeManager.Count - 1)
 
  
            UpdateImage()
 
  
        End  If 
 
  
    End  Sub 
 
  
  
    Private  Sub  UpdateImage()
 
  
        Refresh()
 
  
        Text = String .Format("Объектов: {0}" , m_shapeManager.Count)
 
  
    End  Sub 
 
  
End  Class 
 
  
  
  
Public  Enum  ShapeType
 
  
    Line
 
  
    Rectangle
 
  
    Star
 
  
    Cycle
 
  
End  Enum 
 
  
Public  Interface  IShape
 
  
    Sub  Draw(ByVal  g As  Graphics)
 
  
End  Interface 
 
  
<Serializable()> Public  Class  Line
 
  
    Implements  IShape
 
  
    Public  Sub  New ()
 
  
    End  Sub 
 
  
    Public  Sub  New (ByVal  color__1 As  Color, ByVal  begin__2 As  Point, ByVal  end__3 As  Point, ByVal  width__4 As  Single )
 
  
        Color = color__1
 
  
        Begin = begin__2
 
  
        [End ] = end__3
 
  
        Width = width__4
 
  
    End  Sub 
 
  
  
    Public  Property  Color() As  Color
 
  
        Get 
 
  
            Return  m_Color
 
  
        End  Get 
 
  
        Set (ByVal  value As  Color)
 
  
            m_Color = value
 
  
        End  Set 
 
  
    End  Property 
 
  
    Private  m_Color As  Color
 
  
    Public  Property  Begin() As  Point
 
  
        Get 
 
  
            Return  m_Begin
 
  
        End  Get 
 
  
        Set (ByVal  value As  Point)
 
  
            m_Begin = value
 
  
        End  Set 
 
  
    End  Property 
 
  
    Private  m_Begin As  Point
 
  
    Public  Property  [End ]() As  Point
 
  
        Get 
 
  
            Return  m_End
 
  
        End  Get 
 
  
        Set (ByVal  value As  Point)
 
  
            m_End = value
 
  
        End  Set 
 
  
    End  Property 
 
  
    Private  m_End As  Point
 
  
    Public  Property  Width() As  Single 
 
  
        Get 
 
  
            Return  m_Width
 
  
        End  Get 
 
  
        Set (ByVal  value As  Single )
 
  
            m_Width = value
 
  
        End  Set 
 
  
    End  Property 
 
  
    Private  m_Width As  Single 
 
  
  
    Public  Sub  Draw(ByVal  g As  Graphics) Implements  IShape.Draw
 
  
        Using pen As  New  Pen(Color, Width)
 
  
            pen.StartCap = LineCap.Round
 
  
            pen.EndCap = LineCap.Round
 
  
            g.DrawLine(pen, Begin, [End ])
 
  
        End  Using
 
  
    End  Sub 
 
  
  
End  Class 
 
  
  
Public  Class  ShapeManager
 
  
    Inherits  List(Of IShape)
 
  
    Public  Shared  Function  FromFile(ByVal  path As  String ) As  ShapeManager
 
  
         
  
        Return  Nothing 
 
  
    End  Function 
 
  
    Public  Sub  Save(ByVal  path As  String )
 
  
         
  
    End  Sub 
 
  
End  Class  
 
живое
Ответить 
      
 
     
  
	  
	  
	  
	  Страница:  1   | 2   | 3   | 
 
		
			Поиск по форуму