animateLayout on expanding component is not working - codenameone - codenameone

I went through the ratatouilles-restaurant code in blog. It was great. So I wanted to apply it in my app too but everything works fine except the smooth animation when the component is added. What went wrong in my code? Thankyou in advance.
protected void beforeTeamMemberTry(Form f) {
screenWidth = Display.getInstance().getDisplayWidth();
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
f.add(mainContainer);
for (int i = 0; i < 3; i++) {
Container memberContainer = new Container(new BorderLayout());
memberContainer.getAllStyles().setMargin(5, 5, 0, 0);
mainContainer.add(memberContainer);
Label icon = new Label(theme.getImage("loginBg.png").scaledWidth(screenWidth / 9));
icon.setName("memberIcon");
zeroPaddingMargin(icon);
memberContainer.add(BorderLayout.WEST, icon);
Container detailsContainer = new Container(new BorderLayout());
Container innerContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
detailsContainer.add(BorderLayout.CENTER, innerContainer);
innerContainer.setUIID("innerclkvjd");
zeroPaddingMargin(innerContainer);
innerContainer.getAllStyles().setPadding(10, 0, 10, 0);
innerContainer.getAllStyles().setAlignment(Component.CENTER);
detailsContainer.setName("detailsContainer");
zeroPaddingMargin(detailsContainer);
detailsContainer.getAllStyles().setAlignment(Component.CENTER);
memberContainer.add(BorderLayout.CENTER, detailsContainer);
Button email = new Button("bbeck#gmai.com");
email.setName("memberEmail");
zeroPaddingMargin(email);
innerContainer.add(email);
Label position = new Label("Senior member".toUpperCase());
position.setName("memberPosition");
zeroPaddingMargin(position);
position.getAllStyles().setFgColor(0xccccc0);
position.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
innerContainer.add(position);
Label emblemDown = new Label(">");
emblemDown.setUIID("emblemDown");
memberContainer.add(BorderLayout.EAST, emblemDown);
Label emblemUp = new Label("<");
emblemUp.setUIID("emblemUp");
Container descriptionContainer = new Container();
TextArea descriptionTextArea = new TextArea("slkdjfdlk dslkfdslkf jsdfksdl fksd flksd f;lsdkf sldkf sdlfk s;dl fksdl fksd flsd fkds");
descriptionContainer.add(descriptionTextArea);
descriptionTextArea.setName("memberDescription");
zeroPaddingMargin(descriptionTextArea);
descriptionTextArea.setEditable(false);
descriptionTextArea.setGrowByContent(true);
descriptionTextArea.setGrowLimit(5);
memberContainer.setLeadComponent(email);
email.addActionListener(e -> {
if (emblemDown.getParent() != null) {
memberContainer.add(BorderLayout.EAST, emblemUp);
memberContainer.add(BorderLayout.SOUTH, descriptionContainer);
memberContainer.revalidate();
} else {
memberContainer.removeComponent(emblemUp);
memberContainer.add(BorderLayout.EAST, emblemDown);
memberContainer.removeComponent(descriptionContainer);
memberContainer.revalidate();
}
memberContainer.getParent().animateLayout(300);
});
}
}
Details including phn no. (button) above in descriptionContainer but it cannot be clicked:
Container descriptionContainer = new Container();
TextArea descriptionTextArea = new TextArea("slkdjfdlk dslkfdslkf jsdfksdl fksd flksd f;lsdkf sldkf sdlfk");
descriptionContainer.add(descriptionTextArea);
descriptionTextArea.setGrowByContent(true);
descriptionTextArea.setGrowLimit(2);
Container phnContainer = new Container();
descriptionContainer.add(phnContainer);
Label phnLabel = new Label("Phn: ");
Button phn = new Button("9802921323");
phnContainer.add(phnLabel);
phnContainer.add(phn);
phn.addActionListener(e->{
System.out.println("bibek calls");
});

I have rearranged your code and change your animation code to animateLayoutAndWait(300).
Also you shouldn't call both revalidate() and animateLayout().
I also noticed that your animation was applied to the email button.
Finally, apply the animation to the right container, calling memberContainer.getParent().animateLayout(300); won't animate the emblems but the memberContainer placement.
protected void beforeTeamMemberTry(Form f) {
screenWidth = Display.getInstance().getDisplayWidth();
Container mainContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
f.add(mainContainer);
for (int i = 0; i < 3; i++) {
Container memberContainer = new Container(new BorderLayout());
memberContainer.getAllStyles().setMargin(5, 5, 0, 0);
Label icon = new Label(theme.getImage("loginBg.png").scaledWidth(screenWidth / 9));
icon.setName("memberIcon");
zeroPaddingMargin(icon);
memberContainer.add(BorderLayout.WEST, icon);
Container detailsContainer = new Container(new BorderLayout());
Container innerContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
detailsContainer.add(BorderLayout.CENTER, innerContainer);
innerContainer.setUIID("innerclkvjd");
zeroPaddingMargin(innerContainer);
innerContainer.getAllStyles().setPadding(10, 0, 10, 0);
innerContainer.getAllStyles().setAlignment(Component.CENTER);
detailsContainer.setName("detailsContainer");
zeroPaddingMargin(detailsContainer);
detailsContainer.getAllStyles().setAlignment(Component.CENTER);
memberContainer.add(BorderLayout.CENTER, detailsContainer);
Button email = new Button("bbeck#gmai.com");
email.setName("memberEmail");
zeroPaddingMargin(email);
innerContainer.add(email);
Label position = new Label("Senior member".toUpperCase());
position.setName("memberPosition");
zeroPaddingMargin(position);
position.getAllStyles().setFgColor(0xccccc0);
position.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
innerContainer.add(position);
Label emblemDown = new Label(">");
emblemDown.setUIID("emblemDown");
memberContainer.add(BorderLayout.EAST, emblemDown);
Label emblemUp = new Label("<");
emblemUp.setUIID("emblemUp");
Container descriptionContainer = new Container();
TextArea descriptionTextArea = new TextArea("slkdjfdlk dslkfdslkf jsdfksdl fksd flksd f;lsdkf sldkf sdlfk s;dl fksdl fksd flsd fkds");
descriptionContainer.add(descriptionTextArea);
descriptionTextArea.setName("memberDescription");
zeroPaddingMargin(descriptionTextArea);
descriptionTextArea.setEditable(false);
descriptionTextArea.setGrowByContent(true);
descriptionTextArea.setGrowLimit(5);
memberContainer.setLeadComponent(email);
email.addActionListener(e -> {
if (emblemDown.getParent() != null) {
memberContainer.add(BorderLayout.EAST, emblemUp);
memberContainer.add(BorderLayout.SOUTH, descriptionContainer);
} else {
memberContainer.removeComponent(emblemUp);
memberContainer.add(BorderLayout.EAST, emblemDown);
memberContainer.removeComponent(descriptionContainer);
}
memberContainer.animateLayoutAndWait(300);
});
mainContainer.add(memberContainer);
mainContainer.animateLayoutAndWait(300);
}
}

Related

Adding a dynamically created panel to a Flowlayoutpanel on a user control

I'm working on a todo list application and I'm dynamically building a panel from another form based on user input, this said panel is suppose to be added to the flowlayoutpanel on a user control, but nothing is showing up.
Any ideas what might cause the problem.
Update: my code does work if it is executed directly from the user control itself.
My Code
private void btnCreateTask_Click_1(object sender, EventArgs e)
{
Panel pnlParentTask = new Panel();
pnlParentTask.Size = new Size(234, 89);
pnlParentTask.BorderStyle = BorderStyle.FixedSingle;
pnlParentTask.Location = new Point(217, 186);
PictureBox pbFinish = new PictureBox();
pbFinish.Size = new Size(22, 21);
pbFinish.Location = new Point(13, 13);
pbFinish.BorderStyle = BorderStyle.FixedSingle;
Label lblTitle = new Label();
lblTitle.Text = txtTaskName.Text;
lblTitle.ForeColor = Color.Black;
lblTitle.AutoSize = true;
lblTitle.Location = new Point(41, 12);
lblTitle.Font = new Font("Arial", 12f);
lblTitle.BackColor = Color.Transparent;
lblTitle.Tag = lblTitle.Text;
enc.setpanelTag(lblTitle.Text);
pnlParentTask.Tag = lblTitle.Text;
Label lblDescription = new Label();
lblDescription.Text = txtDescription.Text;
lblDescription.AutoSize = true;
lblDescription.Location = new Point(4, 38);
lblDescription.BackColor = Color.Transparent;
lblDescription.Font = new Font("Microsoft Yahei", 8.25f);
lblDescription.Tag = lblTitle.Text;
PictureBox pbPriority = new PictureBox();
pbPriority.Location = new Point(207, 3);
pbPriority.Tag = lblTitle.Text;
pbPriority.Size = new Size(22, 21);
pbPriority.BorderStyle = BorderStyle.FixedSingle;
Label lblDateCreated = new Label();
lblDateCreated.Location = new Point(3, 69);
lblDateCreated.Text = txtStartDate.Text;
lblDateCreated.BackColor = Color.Transparent;
lblDateCreated.Font = new Font("Microsoft Yahei", 8.25f);
lblDateCreated.Tag = lblTitle.Text;
Label lblDeleteTask = new Label();
lblDeleteTask.Text = "-";
lblDeleteTask.Font = new Font("Microsoft Yahei", 24f);
lblDeleteTask.Location = new Point(206, 53);
lblDeleteTask.Click += new EventHandler(lblRemoveTask_click);
pnlParentTask.Controls.Add(pbFinish);
pnlParentTask.Controls.Add(lblTitle);
pnlParentTask.Controls.Add(lblDescription);
pnlParentTask.Controls.Add(pbPriority);
pnlParentTask.Controls.Add(lblDateCreated);
pnlParentTask.Controls.Add(lblDeleteTask);
priority.flpParent.Controls.Add(pnlParentTask);
this.Close();
}

Add a container to a particular swipe tabs in codename one?

How can I add a container to a particular swipe tabs based on selected Index value of the tabs dynamically?
Here is a simple example that adds a label to the currently selected tab when a button is pressed:
int compIndex = 1;
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Hi World", new BorderLayout());
Tabs tabs = new Tabs();
tabs.addTab("Tab 1", BoxLayout.encloseY(new Label("Tab 1")));
tabs.addTab("Tab 2", BoxLayout.encloseY(new Label("Tab 2")));
tabs.addTab("Tab 3", BoxLayout.encloseY(new Label("Tab 3")));
Button btn = new Button("Add To current");
btn.addActionListener(e->{
((Container)tabs.getSelectedComponent()).add("Added Component "+(compIndex++))
.revalidate();
});
hi.add(BorderLayout.CENTER, tabs).add(BorderLayout.SOUTH, btn);
hi.show();
}
Container can be added to tabs as shown in below.
tabs.addSelectionListener(new SelectionListener() {
#Override
public void selectionChanged(int oldSelected, int newSelected) {
addComponent(newSelected)
}
}
void addContainer(int index){
Container container = new Container();
tabs.addComponent(index, container);
}
void addComponent(int newSelected,NamesListBean nameListBean) {
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer.removeAll();
for(NamesBeans names:nameListBean.getNamesList()){
displayContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
Label name=new Label(names.getNames());
Log.p("names======="+names.getNames());
//displayNamesContainer.removeAll();
//displayNamesContainer.forceRevalidate();
displayContainer.add(name);
}
//getDisplay(displayContainer);
//Container container = new Container();
tabs.addComponent(newSelected, displayContainer);
displayContainer.revalidate();
}
});
public class MaskAndUnMask extends Form{
public MaskAndUnMask(Form current,Resources theme){
this.current=current;
this.theme=theme;
}
public void mask(){
Form hi = new Form("Swipe Tabs", new LayeredLayout());
Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage radioEmptyImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, s);
FontImage radioFullImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, s);
((DefaultLookAndFeel)UIManager.getInstance().getLookAndFeel()).setRadioButtonImages(radioFullImage, radioEmptyImage, radioFullImage, radioEmptyImage);
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
finalRadioList=new ArrayList<String>();
radioList=new ArrayList<RadioButton>();
tabsListName=new ArrayList<String>();
borderLayoutContainer=new Container(new BorderLayout());
radioTypeContainer=new Container();
FlowLayout buttonFlowLayout = new FlowLayout();
buttonFlowLayout.setAlign(Component.CENTER);
radioTypeContainer.setLayout(buttonFlowLayout);
buttonGroup=new ButtonGroup();
displayContainer1=new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer1.setScrollableY(true);
tabs = new Tabs();
divOfRadioButton=totalRecordCount/10;
modOfRadioButton=totalRecordCount%10;
if(modOfRadioButton>0 && modOfRadioButton<9){
totalRadioButton=divOfRadioButton+1;
}else{
totalRadioButton=divOfRadioButton;
}
displayContainer = new Container();
for(i=0;i<totalRadioButton;i++){
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
displayContainer.removeAll();
displayContainer.revalidate();
tabs.addTab("",displayContainer);
tabs.setName("t"+i);
tabs.setTabUIID(tabs.getName());
radioButton =new RadioButton();
radioButton.setName("rbt"+i);
radioTypeContainer.add(radioButton);
finalRadioList.add(radioButton.getName());
tabsListName.add(tabs.getName());
radioList.add(radioButton);
tabIndex0="rbt0";
if(radioList.get(i).getName().equals(tabIndex0)){
radioList.get(i).setSelected(true);
getDisplay(displayContainer);
}
buttonGroup.addAll(radioButton);
}
for(int i=0;i<radioList.size();i++){
radioList.get(i).addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
for(int i=0;i<radioList.size();i++){
radioButtonIndex="t"+buttonGroup.getSelectedIndex();
}
for(int i=0;i<tabsListName.size();i++){
if(radioButtonIndex!=null && radioButtonIndex.equals(tabsListName.get(i))){
tabs.setSelectedIndex(buttonGroup.getSelectedIndex());
}
}
}
});
}
borderLayoutContainer.add(BorderLayout.SOUTH,radioTypeContainer);
tabs.addSelectionListener(new SelectionListener() {
#Override
public void selectionChanged(int oldSelected, int newSelected) {
radioButtonName="rbt"+newSelected;
for(int i=0;i<radioList.size();i++){
if(radioList.get(i).getName().equals(radioButtonName)){
val=newSelected;
if(newSelected==0){
nameListBean = null;
lowerBound=Constants.PAGELOWERBOUND;
upperBound=Constants.PAGEUPPERBOUND;
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}else{
nameListBean = null;
int val=newSelected;
int multipleVal=val*Constants.PAGEUPPERBOUND+1;
lowerBound=multipleVal;
upperBound=multipleVal+9;
nameListBean=getSwipeTabsValues(lowerBound,upperBound);
addComponent(newSelected,nameListBean);
radioList.get(i).setSelected(true);
break;
}
}else{
radioList.get(i).setSelected(false);
}
}
}
void addComponent(int newSelected,NamesListBean nameListBean) {
displayContainer.removeAll();
for(NamesBeans names:nameListBean.getNamesList()){
displayContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Label name=new Label(names.getNames());
displayContainer.add(name);
}
tabs.addComponent(newSelected, displayContainer);
displayContainer.revalidate();
}
});
displayContainer1.add(tabs);
displayContainer1.add(borderLayoutContainer);
hi.add(displayContainer1);
hi.show();
}

Warning paint queue size exceeded, please watch the amount of repaint calls Error

I have about 50 plus rows in the table. If i display them in table as below, "Warning paint queue size exceeded, please watch the amount of repaint calls"
error warning is shown infinitely. If i limit the row to 15 or 20 then it works normally.How can i solve the error.
Update: if i keep "showTableData(f)" in beforeMain, there is no warnings but if i comment it out and keep it in postMain, the warnings appear. Why is that?
#Override
protected void beforeMain(Form f) {
// showTableData(f);
// f.revalidate();
}
Container wrapContainer;
Container containerTableDataGroup;
String detailId = "";
#Override
protected void postMain(Form f) {
showTableData(f); //keeping table data here gives warnings
f.forceRevalidate();
}
public void showTableData(Form f) {
f.setScrollableY(true);
wrapContainer = new Container();
GroupConnection gc = new GroupConnection();
for (int i = 0; i < 200; i++) {
Container tableNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea tableNameData = new TextArea();
tableNameData.setText("tableNameData");
stylingTextArea(tableNameData);
tableNameData.setActAsLabel(true);
tableNameDataContainer.add(tableNameData);
Container inaugurationDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea inaugurationDateData = new TextArea();
inaugurationDateData.setText("inaugurationDate");
stylingTextArea(inaugurationDateData);
inaugurationDateData.setActAsLabel(true);
inaugurationDateDataContainer.add(inaugurationDateData);
Container areaCodeDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea areaCodeData = new TextArea();
areaCodeData.setText("areaCodeData");
stylingTextArea(areaCodeData);
areaCodeData.setActAsLabel(true);
areaCodeDataContainer.add(areaCodeData);
Container clubAbbrNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubAbbrNameData = new TextArea();
clubAbbrNameData.setText("clubAbbrNameData");
stylingTextArea(clubAbbrNameData);
clubAbbrNameData.setActAsLabel(true);
clubAbbrNameDataContainer.add(clubAbbrNameData);
Container clubCharterDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubCharterDateData = new TextArea();
clubCharterDateData.setText("clubCharterDateData");
stylingTextArea(clubCharterDateData);
clubCharterDateData.setActAsLabel(true);
clubCharterDateDataContainer.add(clubCharterDateData);
TableLayout tl1 = new TableLayout(1, 5);
containerTableDataGroup = new Container(tl1);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(30), tableNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), inaugurationDateDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), areaCodeDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(15), clubAbbrNameDataContainer);
containerTableDataGroup.add(tl1.createConstraint().widthPercentage(20), clubCharterDateDataContainer);
wrapContainer.add(containerTableDataGroup);
}
f.add(wrapContainer);
wrapContainer.revalidate();
}
public void stylingTextArea(TextArea textAreaName) {
textAreaName.setUIID("styleTextArea");
textAreaName.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
textAreaName.getAllStyles().setPadding(0, 0, 0, 0);
textAreaName.getAllStyles().setAlignment(Component.CENTER);
textAreaName.setEditable(false);
textAreaName.setGrowByContent(true);
textAreaName.setGrowLimit(2);
}
Update 2:
If I keep connection in beforeForm method using addToQueue, the blank screen is displayed. If i use addToQueueAndWait, the infinite progress is shown only for a short period of time, only couple of seconds later the datas are displayed(smtimes take much more time to display). I had used actionlistener callback in connection request method in postForm and addToQueue works but same is not working in beforeForm.
protected void beforeGroups(Form f) {
groupConnection();
wrapContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for (Map<String, Object> element : response) {
String tableName = (String) element.get("name");
. . . . . . .
. . . . . . .
}
}
void groupConnection() {
ConnectionRequest connectionRequest = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
response = (ArrayList<Map<String, Object>>) parsedData.get("root");
}
};
connectionRequest.setUrl(allUrl.groupsUrl);
InfiniteProgress ip = new InfiniteProgress();
Dialog d = ip.showInifiniteBlocking();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);//blank screen if addToQueueAndWait isnot used here
}
Update 3:
#Override
protected void beforeAbc(Form f) {
minuteConnection(f);
}
void minuteConnection(Form f) {
ConnectionRequest connectionRequest = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
JSONParser jSONParser = new JSONParser();
Map<String, Object> parsedData = jSONParser.parseJSON(new InputStreamReader(input));
responsee = (ArrayList<Map<String, Object>>) parsedData.get("root");
}
#Override
protected void postResponse() {
int i = 0;
wrapContainerMeeting = new Container(new BoxLayout(BoxLayout.Y_AXIS));
for (Map<String, Object> element : responsee) {
String minuteId = (String) element.get("meetingNumberId");
String tblId = (String) element.get("tbladmin_id");
String tableName = (String) element.get("name");
String totalMembers = (String) element.get("continousMeetingNumber");
String totalMeetingYearly = (String) element.get("meetingForYear");
String minuteDate = (String) element.get("meetingDate");
Container tableNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea tableNameDataMeeting = new TextArea(tableName);
tableNameDataContainer.add(tableNameDataMeeting);
Container inaugurationDateDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea inaugurationDateDataMeeting = new TextArea(totalMembers);
inaugurationDateDataContainer.add(inaugurationDateDataMeeting);
Container areaCodeDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea areaCodeData = new TextArea(totalMeetingYearly);
areaCodeDataContainer.add(areaCodeData);
Container clubAbbrNameDataContainer = new Container(new FlowLayout(Component.CENTER, Component.CENTER));
TextArea clubAbbrNameData = new TextArea(minuteDate);
clubAbbrNameDataContainer.add(clubAbbrNameData);
}
f.add(wrapContainerMeeting);
}
};
AllUrl allUrl = new AllUrl();
connectionRequest.setUrl(allUrl.abcUrl);
connectionRequest.setPost(false);//keeping this line or deleting doesnt affect anything
InfiniteProgress ip = new InfiniteProgress();
Dialog d = ip.showInifiniteBlocking();
connectionRequest.setDisposeOnCompletion(d);
NetworkManager.getInstance().addToQueue(connectionRequest);
}
You call revalidate for every single row you add which is very excessive...
You need to do this once after you finish adding everything.

Print Grid which generated dynamically in wpf

i want to print a grid which is generated dynamically.
Means, in the click event of the Print Button, i m generating a grid and then i want to print that grid.
here is my code,
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
PrintDialog Objprint = new System.Windows.Controls.PrintDialog();
if (Objprint.ShowDialog() == true)
{
System.Printing.PrintCapabilities capabilities = Objprint.PrintQueue.GetPrintCapabilities(Objprint.PrintTicket);
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / this.ActualWidth, capabilities.PageImageableArea.ExtentHeight / this.ActualHeight);
#region "Make a grid For Printing"
Grid objgrid = new Grid();
objgrid.Name = "GridForPrinting";
objgrid.Width = 1000;
objgrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
objgrid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
objgrid.RowDefinitions.Add(new RowDefinition());
TextBlock objtext = new TextBlock();
objtext.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
objtext.VerticalAlignment = System.Windows.VerticalAlignment.Center;
objtext.Text = "SUPERIOR COURT OF CALIF COUNTY OF SAN BERNARDINO";
Grid.SetRow(objtext, 0);
objgrid.Children.Add(objtext);
#endregion
Objprint.PrintVisual(objgrid, "Case Summary");
}
}
this code give me blank page to print.
how can i do that?
here i get answer,
from the below code i get what i want to do...
void PrintOnClick(object sender, RoutedEventArgs args)
{
PrintDialog dlg = new PrintDialog();
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
// Create Grid panel.
Grid grid = new Grid();
// Define 5 auto-sized rows and columns.
for (int i = 0; i < 5; i++)
{
ColumnDefinition coldef = new ColumnDefinition();
coldef.Width = GridLength.Auto;
grid.ColumnDefinitions.Add(coldef);
RowDefinition rowdef = new RowDefinition();
rowdef.Height = GridLength.Auto;
grid.RowDefinitions.Add(rowdef);
}
// Give the Grid a gradient brush.
grid.Background =
new LinearGradientBrush(Colors.Black, Colors.White,
new Point(0, 0), new Point(1, 1));
// Every program needs some randomness.
Random rand = new Random();
// Fill the Grid with 25 buttons.
for (int i = 0; i < 25; i++)
{
Button btn = new Button();
btn.FontSize = 12 + rand.Next(8);
btn.Content = "Button No. " + (i + 1);
btn.HorizontalAlignment = HorizontalAlignment.Center;
btn.VerticalAlignment = VerticalAlignment.Center;
btn.Margin = new Thickness(6);
grid.Children.Add(btn);
Grid.SetRow(btn, i % 5);
Grid.SetColumn(btn, i / 5);
}
// Size the Grid.
grid.Measure(new Size(Double.PositiveInfinity,
Double.PositiveInfinity));
Size sizeGrid = grid.DesiredSize;
// Determine point for centering Grid on page.
Point ptGrid =
new Point((dlg.PrintableAreaWidth - sizeGrid.Width) / 2,
(dlg.PrintableAreaHeight - sizeGrid.Height) / 2);
// Layout pass.
grid.Arrange(new Rect(ptGrid, sizeGrid));
// Now print it.
dlg.PrintVisual(grid, Title);
}
}
The PrintVisual print a Visual object. That means, by using the PrintVisual method, we can print any control, container, Window or user control that is in the visualtree.You cannot print a control that is not in the visualtree

Scaled ellipse over button, button not clickable

I'm scaling an ellipse in an animation with the following code:
ScaleTransform myScTransform = new ScaleTransform();
TransformGroup myTransGroup = new TransformGroup();
myTransGroup.Children.Add(myScTransform);
newPHRadio.RenderTransform = myTransGroup;
newPHRadio.RenderTransformOrigin = new Point(0.5, 0.5);
Storyboard story = new Storyboard();
DoubleAnimation xAnimation = new DoubleAnimation(1, ph.Bereik, new Duration(TimeSpan.FromSeconds(2)));
DoubleAnimation yAnimation = new DoubleAnimation(1, ph.Bereik, new Duration(TimeSpan.FromSeconds(2)));
DoubleAnimation doorzichtig = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(2)));
Storyboard.SetTarget(xAnimation, newPHRadio);
Storyboard.SetTarget(yAnimation, newPHRadio);
Storyboard.SetTarget(doorzichtig, newPHRadio);
DependencyProperty[] propertyChainX = new DependencyProperty[] {
Ellipse.RenderTransformProperty,
TransformGroup.ChildrenProperty,
ScaleTransform.ScaleXProperty
};
DependencyProperty[] propertyChainY = new DependencyProperty[] {
Ellipse.RenderTransformProperty,
TransformGroup.ChildrenProperty,
ScaleTransform.ScaleYProperty
};
string thePath = "(0).(1)[0].(2)";
Storyboard.SetTargetProperty(xAnimation, new PropertyPath(thePath, propertyChainX));
Storyboard.SetTargetProperty(yAnimation, new PropertyPath(thePath, propertyChainY));
Storyboard.SetTargetProperty(doorzichtig, new PropertyPath(Ellipse.OpacityProperty));
story.Children.Add(xAnimation);
story.Children.Add(yAnimation);
story.Children.Add(doorzichtig);
story.Duration = new Duration(TimeSpan.FromSeconds(60 / ph.Frequentie));
story.RepeatBehavior = RepeatBehavior.Forever;
story.Begin();
The ellipse is constructed with the following code:
Ellipse newPHRadio = new Ellipse();
newPHRadio.Width = 1;
newPHRadio.Height = 1;
newPHRadio.SetValue(Canvas.LeftProperty, ph.xPositie + 7);
newPHRadio.SetValue(Canvas.TopProperty, ph.yPositie + 7);
newPHRadio.SetValue(Canvas.ZIndexProperty, 3);
newPHRadio.Stroke = new SolidColorBrush(Colors.Black);
newPHRadio.StrokeThickness = 0.03;
Now the ellipse is scaled over an button which has a z-index of 1. With a static ellipse and no fill, the button is clickable. Now there is no fill as well but the button is not clickable. Can someone tell me how to fix this?
With the code you provided the button is clickable.
But if you set the Fill of the ellipse to anything but null, even to Brushes.Transparent, the click will not make it to the button anymore.
Try explicitly setting the Fill of the ellipse to null:
newPHRadio.Fill = null;

Resources