sábado, 28 de julho de 2012

C# - Como carregar uma dll


[DllImport(@"C:\Users\CPD-01\Desktop\Dll\DllSample.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]

private static extern int funcao(int valor);

Asp.Net - Carregar os dados de um GridView com TextBox


            ed = new TESTEEntities();
            for (int i = 0; i < GridDados.Rows.Count; i++)
            {
                 TABELA objFreq = new TABELA()
                {
                    ANO = dropAno.SelectedValue,
                    MES = dropMes.SelectedValue,
                    ID = GridDados.Rows[GridDados.Rows[i].DataItemIndex].Cells[0].Text.ToString(),
                    NOME = GridDados.Rows[GridDados.Rows[i].DataItemIndex].Cells[1].Text.ToString(),
                    DATA_NASCIMENTO = DateTime.Parse(GridDados.Rows[GridDados.Rows[i].DataItemIndex].Cells[2].Text.ToString()),

                    TOTAL = int.Parse(Request.Form["ctl00$MainContent$GridDados$ctl0"+(i+2).ToString()+"$TextBox1"])
                };

                ed.AddToFREQUENCIA(objFreq);
                ed.SaveChanges();
            }

Asp.Net - Obter valor usando o request.Form


 protected void Button1_Click(object sender, EventArgs e)
 {
        string str = Request.Form["ctl00$ContentPlaceHolder1$TextBox1"];
 }

sexta-feira, 6 de julho de 2012

Delphi - Drag and Drop usando o Treeview com Richedit



procedure TForm1.RichEdit1DragDrop(Sender, Source: TObject; X, Y: Integer);
var ponteiro : Tpoint;
    index: integer;
begin
  ponteiro:= Point( X, Y );
  Richedit1 := sender as TRichedit;
  index := Richedit1.perform(Messages.EM_CHARFROMPOS, 0,integer(@ponteiro));
  if index >= 0 Then
    begin
      Richedit1.selstart := index;
      RichEdit1.SelText := TreeView1.Selected.Text;
    end;
end;

procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
 Accept := (Source is TTreeView);
end;

domingo, 1 de julho de 2012

Delphi - Alterar cor da fonte do groupBox no Delphi XE


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, themes;

type
   TGroupBox = class(StdCtrls.TGroupBox) //declare this before of your form definition
    public
    procedure Paint; override;
  end;

type
  TForm1 = class(TForm)

    GroupBox1: TGroupBox;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TGroupBox.Paint;
var
  H: Integer;
  R: TRect;
  Flags: Longint;
  CaptionRect,
  OuterRect: TRect;
  Size: TSize;
  Box: TThemedButton;
  Details: TThemedElementDetails;
begin
  with Canvas do
  begin
    Font := Self.Font;

    if ThemeControl(Self) then
    begin
      if Text <> '' then
      begin
        GetTextExtentPoint32(Handle, PChar(Text), Length(Text), Size);
        CaptionRect := Rect(0, 0, Size.cx, Size.cy);
        if not UseRightToLeftAlignment then
          OffsetRect(CaptionRect, 8, 0)
        else
          OffsetRect(CaptionRect, Width - 8 - CaptionRect.Right, 0);
      end
      else
        CaptionRect := Rect(0, 0, 0, 0);

      OuterRect := ClientRect;
      OuterRect.Top := (CaptionRect.Bottom - CaptionRect.Top) div 2;
      with CaptionRect do
        ExcludeClipRect(Handle, Left, Top, Right, Bottom);
      if Enabled then
        Box := tbGroupBoxNormal
      else
        Box := tbGroupBoxDisabled;
      Details := ThemeServices.GetElementDetails(Box);

      //Draw the themed frame
      ThemeServices.DrawElement(Handle, Details, OuterRect);
      SelectClipRgn(Handle, 0);
      if Text <> '' then
      begin
         H := TextHeight('0');
         if not UseRightToLeftAlignment then
           R := Rect(8, 0, 0, H)
         else
           R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H);
         Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);

         //Now using the Windows.DrawText
         DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT);
         Brush.Color := Color; //Cor de Fundo
         Font.Color := clBlue; //Cor da Fonte
         DrawText(Handle, PChar(Text), Length(Text), R, Flags);
      end;
    end
    else
    inherited;   //Herdando da classe paint.
  end;
end;

end.